From 4b123a5347d0f16003feb045a5304bbb91630d74 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 25 Nov 2013 23:01:23 +0100 Subject: [PATCH] fixed a bug with multiple ob_start() on http\Env\Response while replacing it's body --- package.xml | 8 ++++---- php_http.h | 2 +- php_http_env_response.c | 8 +++----- php_http_message.c | 12 ++++++++++-- php_http_message.h | 1 + php_http_message_body.c | 4 ++++ tests/envresponse015.phpt | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 tests/envresponse015.phpt diff --git a/package.xml b/package.xml index c12796c..e9b5014 100644 --- a/package.xml +++ b/package.xml @@ -39,7 +39,7 @@ v2: http://dev.iworks.at/ext-http/lcov/ext/http/ 2013-11-22 - 2.0.0 + 2.0.1 2.0.0 @@ -48,9 +48,8 @@ v2: http://dev.iworks.at/ext-http/lcov/ext/http/ BSD, revised @@ -180,6 +179,7 @@ Keep in mind that it's got the major version 2, because it's incompatible with p + diff --git a/php_http.h b/php_http.h index 6daa204..4ceb8f0 100644 --- a/php_http.h +++ b/php_http.h @@ -13,7 +13,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define PHP_PECL_HTTP_VERSION "2.0.0" +#define PHP_PECL_HTTP_VERSION "2.0.1dev" extern zend_module_entry http_module_entry; #define phpext_http_ptr &http_module_entry diff --git a/php_http_env_response.c b/php_http_env_response.c index cb52752..cc9d30c 100644 --- a/php_http_env_response.c +++ b/php_http_env_response.c @@ -1089,11 +1089,9 @@ static PHP_METHOD(HttpEnvResponse, __invoke) PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj); - if (obj->body || SUCCESS == php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), (void *) &obj->body TSRMLS_CC)) { - php_http_message_body_append(obj->message->body, ob_str, ob_len); - RETURN_TRUE; - } - RETURN_FALSE; + php_http_message_object_init_body_object(obj); + php_http_message_body_append(obj->message->body, ob_str, ob_len); + RETURN_TRUE; } } diff --git a/php_http_message.c b/php_http_message.c index f3509a4..6adc557 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -782,6 +782,14 @@ STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval return SUCCESS; } +STATUS php_http_message_object_init_body_object(php_http_message_object_t *obj) +{ + TSRMLS_FETCH_FROM_CTX(obj); + + php_http_message_body_addref(obj->message->body); + return php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, (void *) &obj->body TSRMLS_CC); +} + zend_object_value php_http_message_object_new(zend_class_entry *ce TSRMLS_DC) { return php_http_message_object_new_ex(ce, NULL, NULL TSRMLS_CC); @@ -1050,8 +1058,8 @@ static PHP_METHOD(HttpMessage, getBody) PHP_HTTP_MESSAGE_OBJECT_INIT(obj); if (!obj->body) { - php_http_message_body_addref(obj->message->body); - php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, (void *) &obj->body TSRMLS_CC); + php_http_message_object_init_body_object(obj); + } if (obj->body) { RETVAL_OBJVAL(obj->body->zv, 1); diff --git a/php_http_message.h b/php_http_message.h index 32af834..6ef7298 100644 --- a/php_http_message.h +++ b/php_http_message.h @@ -83,6 +83,7 @@ PHP_MSHUTDOWN_FUNCTION(http_message); void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool top /* = 1 */ TSRMLS_DC); void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC); STATUS php_http_message_object_set_body(php_http_message_object_t *obj, zval *zbody TSRMLS_DC); +STATUS php_http_message_object_init_body_object(php_http_message_object_t *obj); zend_object_value php_http_message_object_new(zend_class_entry *ce TSRMLS_DC); zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_message_t *msg, php_http_message_object_t **ptr TSRMLS_DC); diff --git a/php_http_message_body.c b/php_http_message_body.c index 2749fac..0337aa6 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -55,6 +55,10 @@ php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **bo } TSRMLS_SET_CTX(body->ts); + if (body_ptr) { + *body_ptr = body; + } + return body; } diff --git a/tests/envresponse015.phpt b/tests/envresponse015.phpt new file mode 100644 index 0000000..abad2bb --- /dev/null +++ b/tests/envresponse015.phpt @@ -0,0 +1,36 @@ +--TEST-- +env response send replaced body using multiple ob_start +--SKIPIF-- + +--FILE-- +getBody(); +$r->setBody(new http\Message\Body); + +ob_start($r); +echo "foo: $b\n"; +ob_end_flush(); + +$f = fopen("php://memory", "r+"); + +$r->send($f); + +fseek($f, 0, SEEK_SET); +echo stream_get_contents($f); + +?> +--EXPECT-- +HTTP/1.1 200 OK +Accept-Ranges: bytes +ETag: "fc8305a1" + +foo: bar -- 2.30.2