- fix crash with custom content-type when no other options are set
authorMichael Wallner <mike@php.net>
Wed, 28 Dec 2005 21:48:03 +0000 (21:48 +0000)
committerMichael Wallner <mike@php.net>
Wed, 28 Dec 2005 21:48:03 +0000 (21:48 +0000)
- add xmlrpc test

http_request_object.c
tests/HttpRequest_006.phpt [new file with mode: 0644]

index f763b482898c408613dcb5fade3891035e51909c..d2a51921d547cfba1cf14058cb1c464ce9a273b4 100644 (file)
@@ -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 (file)
index 0000000..57eda66
--- /dev/null
@@ -0,0 +1,144 @@
+--TEST--
+HttpRequest XMLRPC
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkext('xmlrpc');
+checkcls('HttpRequest');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HTTP_METH_POST);
+$r->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) "<?xml version="1.0" encoding="iso-8859-1"?>
+<methodCall>
+<methodName>testMethod</methodName>
+<params>
+ <param>
+  <value>
+   <struct>
+    <member>
+     <name>foo</name>
+     <value>
+      <string>bar</string>
+     </value>
+    </member>
+   </struct>
+  </value>
+ </param>
+</params>
+</methodCall>
+"
+
+"
+}
+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) "<?xml version="1.0" encoding="iso-8859-1"?>
+<methodCall>
+<methodName>testMethod</methodName>
+<params>
+ <param>
+  <value>
+   <struct>
+    <member>
+     <name>foo</name>
+     <value>
+      <string>bar</string>
+     </value>
+    </member>
+   </struct>
+  </value>
+ </param>
+</params>
+</methodCall>
+"
+
+"
+}
+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) "<?xml version="1.0" encoding="iso-8859-1"?>
+<methodCall>
+<methodName>testMethod</methodName>
+<params>
+ <param>
+  <value>
+   <struct>
+    <member>
+     <name>foo</name>
+     <value>
+      <string>bar</string>
+     </value>
+    </member>
+   </struct>
+  </value>
+ </param>
+</params>
+</methodCall>
+"
+
+"
+}
+Done