From fc86bad83e836bbf363e82ed47cf3943795c45b3 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 24 Apr 2014 11:01:27 +0200 Subject: [PATCH] reset the content length when the body was reset --- php_http_message.c | 8 ++++++++ tests/client014.phpt | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/client014.phpt diff --git a/php_http_message.c b/php_http_message.c index 0ffdd9e..8c1f40c 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -300,6 +300,14 @@ void php_http_message_update_headers(php_http_message_t *msg) zval_ptr_dtor(&h); } } + } else if ((h = php_http_message_header(msg, ZEND_STRL("Content-Length"), 1))) { + zval *h_cpy = php_http_ztyp(IS_LONG, h); + + zval_ptr_dtor(&h); + if (Z_LVAL_P(h_cpy)) { + zend_hash_del(&msg->hdrs, "Content-Length", sizeof("Content-Length")); + } + zval_ptr_dtor(&h_cpy); } } diff --git a/tests/client014.phpt b/tests/client014.phpt new file mode 100644 index 0000000..d0ff471 --- /dev/null +++ b/tests/client014.phpt @@ -0,0 +1,26 @@ +--TEST-- +reset content length when resetting body +--SKIPIF-- + +--FILE-- +setBody(new http\Message\Body(fopen(__FILE__, "r"))); +$client->enqueue($request); +var_dump($request->getHeader("Content-Length")); +$request->setBody(new http\Message\Body); +$client->requeue($request); +var_dump($request->getHeader("Content-Length")); +?> +===DONE=== +--EXPECTF-- +Test +int(379) +bool(false) +===DONE=== -- 2.30.2