From 31f84f4c72ac138ba62df4f56ae23dc76bc20963 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 17 Mar 2009 07:55:50 +0000 Subject: [PATCH] fix HttpMessage::toMessageTypeObject(), thanks Rob --- http_message_api.c | 30 +++++++++++++++++++++++++++- http_message_object.c | 4 +++- package2.xml | 2 +- php_http.h | 2 +- tests/HttpMessage_008.phpt | 41 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 tests/HttpMessage_008.phpt 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/package2.xml b/package2.xml index 96fc86a..036eeb0 100644 --- a/package2.xml +++ b/package2.xml @@ -30,7 +30,7 @@ support. Parallel requests are available for PHP 5 and greater. 2009-02-12 - 1.6.3 + 1.6.4-dev 1.6.0 diff --git a/php_http.h b/php_http.h index 56b6b52..8ca1f55 100644 --- a/php_http.h +++ b/php_http.h @@ -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 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 -- 2.30.2