fix HttpMessage::toMessageTypeObject()
authorMichael Wallner <mike@php.net>
Tue, 17 Mar 2009 07:56:39 +0000 (07:56 +0000)
committerMichael Wallner <mike@php.net>
Tue, 17 Mar 2009 07:56:39 +0000 (07:56 +0000)
http_message_api.c
http_message_object.c
tests/HttpMessage_008.phpt [new file with mode: 0644]

index 17f6c77..e85774f 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 6d271ba..5b96d21 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
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