From: Michael Wallner Date: Tue, 17 Mar 2009 07:56:39 +0000 (+0000) Subject: fix HttpMessage::toMessageTypeObject() X-Git-Tag: RELEASE_1_7_0b2~30 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=01300e3808fec53def73a410233f68f36f292097 fix HttpMessage::toMessageTypeObject() --- diff --git a/http_message_api.c b/http_message_api.c index 17f6c77..e85774f 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -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; } diff --git a/http_message_object.c b/http_message_object.c index 6d271ba..5b96d21 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -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 index 0000000..66e41dc --- /dev/null +++ b/tests/HttpMessage_008.phpt @@ -0,0 +1,41 @@ +--TEST-- +HttpMessage::toMessageTypeObject() +--SKIPIF-- + +--FILE-- +"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