fix HttpMessage::toMessageTypeObject(), thanks Rob
authorMichael Wallner <mike@php.net>
Tue, 17 Mar 2009 07:55:50 +0000 (07:55 +0000)
committerMichael Wallner <mike@php.net>
Tue, 17 Mar 2009 07:55:50 +0000 (07:55 +0000)
http_message_api.c
http_message_object.c
package2.xml
php_http.h
tests/HttpMessage_008.phpt [new file with mode: 0644]

index 17f6c7796a18f003336212521affb5a1dd2ba86d..e85774fbb1c7d25a191554180b5bea75a9aefbb5 100644 (file)
@@ -397,13 +397,41 @@ PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_
                        zval **single_header;
 
                        switch (Z_TYPE_PP(header)) {
+                               case IS_BOOL:
+                                       phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_BVAL_PP(header)?"true":"false");
+                                       break;
+                                       
+                               case IS_LONG:
+                                       phpstr_appendf(&str, "%s: %ld" HTTP_CRLF, key.str, Z_LVAL_PP(header));
+                                       break;
+                                       
+                               case IS_DOUBLE:
+                                       phpstr_appendf(&str, "%s: %f" HTTP_CRLF, key.str, Z_DVAL_PP(header));
+                                       break;
+                                       
                                case IS_STRING:
                                        phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_STRVAL_PP(header));
                                        break;
 
                                case IS_ARRAY:
                                        FOREACH_VAL(pos2, *header, single_header) {
-                                               phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_STRVAL_PP(single_header));
+                                               switch (Z_TYPE_PP(single_header)) {
+                                                       case IS_BOOL:
+                                                               phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_BVAL_PP(single_header)?"true":"false");
+                                                               break;
+                                                               
+                                                       case IS_LONG:
+                                                               phpstr_appendf(&str, "%s: %ld" HTTP_CRLF, key.str, Z_LVAL_PP(single_header));
+                                                               break;
+                                                               
+                                                       case IS_DOUBLE:
+                                                               phpstr_appendf(&str, "%s: %f" HTTP_CRLF, key.str, Z_DVAL_PP(single_header));
+                                                               break;
+                                                               
+                                                       case IS_STRING:
+                                                               phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_STRVAL_PP(single_header));
+                                                               break;
+                                               }
                                        }
                                        break;
                        }
index 6d271ba9b0c22f436de22e60b181eb450eb3b253..5b96d218076ee4caea914895a209b2b813e9fdae 100644 (file)
@@ -802,7 +802,8 @@ PHP_METHOD(HttpMessage, setBody)
        
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &body, &len)) {
                phpstr_dtor(PHPSTR(obj->message));
-               phpstr_from_string_ex(PHPSTR(obj->message), body, len);         
+               phpstr_from_string_ex(PHPSTR(obj->message), body, len);
+               phpstr_fix(PHPSTR(obj->message));
        }
 }
 /* }}} */
@@ -1287,6 +1288,7 @@ PHP_METHOD(HttpMessage, toMessageTypeObject)
                                                zval_copy_ctor(&body);
                                                sapi_module.treat_data(PARSE_STRING, Z_STRVAL(body), &post TSRMLS_CC);
                                                zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setpostfields", NULL, &post);
+                                               zval_dtor(&post);
                                        }
                                }
 #else
index 96fc86a089f647a9e4b4ec82375b5a13b7e006fa..036eeb08617b0f9594b51a6cc4d8544053147863 100644 (file)
@@ -30,7 +30,7 @@ support. Parallel requests are available for PHP 5 and greater.
  </lead>
  <date>2009-02-12</date>
  <version>
-  <release>1.6.3</release>
+  <release>1.6.4-dev</release>
   <api>1.6.0</api>
  </version>
  <stability>
index 56b6b526b79bf2c6ac1cc3fb29f96f4e5c1e75e2..8ca1f55cd093213089b80894aac8064b392edddc 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef PHP_EXT_HTTP_H
 #define PHP_EXT_HTTP_H
 
-#define PHP_HTTP_VERSION "1.6.3"
+#define PHP_HTTP_VERSION "1.6.4-dev"
 
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
diff --git a/tests/HttpMessage_008.phpt b/tests/HttpMessage_008.phpt
new file mode 100644 (file)
index 0000000..66e41dc
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+HttpMessage::toMessageTypeObject()
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkver(5);
+checkcls('HttpRequest');
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+$b = HttpRequest::encodeBody(array("a"=>"b",1=>2),null);
+
+$m = new HttpMessage;
+$m->setType(HttpMessage::TYPE_REQUEST);
+$m->setRequestMethod('POST');
+$m->setRequestUrl("http://www.example.com");
+$m->setHttpVersion('1.1');
+$m->addHeaders(
+       array(
+               "Content-Type"  => "application/x-www-form-urlencoded",
+               "Host"                  => "www.example.com",
+               "Content-Length"=> strlen($b),
+       )
+);
+$m->setBody($b);
+$r = $m->toMessageTypeObject();
+echo $m,"\n";
+echo "Done\n";
+?>
+--EXPECTF--
+%aTEST
+POST http://www.example.com HTTP/1.1
+Content-Type: application/x-www-form-urlencoded
+Host: www.example.com
+Content-Length: 7
+
+a=b&1=2
+
+Done