From: Michael Wallner Date: Wed, 28 Dec 2005 21:48:03 +0000 (+0000) Subject: - fix crash with custom content-type when no other options are set X-Git-Tag: RELEASE_0_21_0~19 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ec355cdc412e40500bdaa5ba37b82905e212824b;p=m6w6%2Fext-http - fix crash with custom content-type when no other options are set - add xmlrpc test --- diff --git a/http_request_object.c b/http_request_object.c index f763b48..d2a5192 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -465,7 +465,9 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ if (Z_STRLEN_P(ctype)) { zval **headers, *opts = GET_PROP(obj, options); - if ((SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) && (Z_TYPE_PP(headers) == IS_ARRAY)) { + if ( (Z_TYPE_P(opts) == IS_ARRAY) && + (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) && + (Z_TYPE_PP(headers) == IS_ARRAY)) { zval **ct_header; /* only override if not already set */ @@ -478,7 +480,8 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ MAKE_STD_ZVAL(headers); array_init(headers); add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1); - add_assoc_zval(opts, "headers", headers); + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers); + zval_ptr_dtor(&headers); } } diff --git a/tests/HttpRequest_006.phpt b/tests/HttpRequest_006.phpt new file mode 100644 index 0000000..57eda66 --- /dev/null +++ b/tests/HttpRequest_006.phpt @@ -0,0 +1,144 @@ +--TEST-- +HttpRequest XMLRPC +--SKIPIF-- + +--FILE-- +setContentType('text/xml'); +$r->setRawPostData(xmlrpc_encode_request('testMethod', array('foo' => 'bar'))); +var_dump($r->send()); +var_dump($r->send()); +var_dump($r->send()); + +echo "Done\n"; +?> +--EXPECTF-- +%sTEST +object(HttpMessage)#%d (%d) { + ["type:protected"]=> + int(2) + ["httpVersion:protected"]=> + float(1.1) + ["responseCode:protected"]=> + int(200) + ["responseStatus:protected"]=> + string(2) "OK" + ["requestMethod:protected"]=> + string(0) "" + ["requestUri:protected"]=> + string(0) "" + ["headers:protected"]=> + array(6) { + %s + } + ["body:protected"]=> + string(310) "string(294) " + +testMethod + + + + + + foo + + bar + + + + + + + +" + +" +} +object(HttpMessage)#%d (%d) { + ["type:protected"]=> + int(2) + ["httpVersion:protected"]=> + float(1.1) + ["responseCode:protected"]=> + int(200) + ["responseStatus:protected"]=> + string(2) "OK" + ["requestMethod:protected"]=> + string(0) "" + ["requestUri:protected"]=> + string(0) "" + ["headers:protected"]=> + array(6) { + %s + } + ["body:protected"]=> + string(310) "string(294) " + +testMethod + + + + + + foo + + bar + + + + + + + +" + +" +} +object(HttpMessage)#%d (%d) { + ["type:protected"]=> + int(2) + ["httpVersion:protected"]=> + float(1.1) + ["responseCode:protected"]=> + int(200) + ["responseStatus:protected"]=> + string(2) "OK" + ["requestMethod:protected"]=> + string(0) "" + ["requestUri:protected"]=> + string(0) "" + ["headers:protected"]=> + array(6) { + %s + } + ["body:protected"]=> + string(310) "string(294) " + +testMethod + + + + + + foo + + bar + + + + + + + +" + +" +} +Done