fixed a bug with multiple ob_start() on http\Env\Response while replacing it's body
authorMichael Wallner <mike@php.net>
Mon, 25 Nov 2013 22:01:23 +0000 (23:01 +0100)
committerMichael Wallner <mike@php.net>
Mon, 25 Nov 2013 22:01:23 +0000 (23:01 +0100)
package.xml
php_http.h
php_http_env_response.c
php_http_message.c
php_http_message.h
php_http_message_body.c
tests/envresponse015.phpt [new file with mode: 0644]

index c12796c..e9b5014 100644 (file)
@@ -39,7 +39,7 @@ v2: http://dev.iworks.at/ext-http/lcov/ext/http/
  </lead>
  <date>2013-11-22</date>
  <version>
-  <release>2.0.0</release>
+  <release>2.0.1</release>
   <api>2.0.0</api>
  </version>
  <stability>
@@ -48,9 +48,8 @@ v2: http://dev.iworks.at/ext-http/lcov/ext/http/
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
-Extended HTTP support. Again. 
-        
-Keep in mind that it's got the major version 2, because it's incompatible with pecl_http v1.
+* Fixed a bug with multiple ob_start(http\Env\Response) while replacing the body
+* Some Windows fixes
 ]]></notes>
  <contents>
   <dir name="/">
@@ -180,6 +179,7 @@ Keep in mind that it's got the major version 2, because it's incompatible with p
      <file role="test" name="envresponse012.phpt"/>
      <file role="test" name="envresponse013.phpt"/>
      <file role="test" name="envresponse014.phpt"/>
+     <file role="test" name="envresponse015.phpt"/>
      <file role="test" name="envresponsebody001.phpt"/>
      <file role="test" name="envresponsebody002.phpt"/>
      <file role="test" name="envresponsecodes.phpt"/>
index 6daa204..4ceb8f0 100644 (file)
@@ -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
index cb52752..cc9d30c 100644 (file)
@@ -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;
        }
 }
 
index f3509a4..6adc557 100644 (file)
@@ -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);
index 32af834..6ef7298 100644 (file)
@@ -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);
index 2749fac..0337aa6 100644 (file)
@@ -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 (file)
index 0000000..abad2bb
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+env response send replaced body using multiple ob_start
+--SKIPIF--
+<?php
+include "skipif.inc";
+?>
+--FILE--
+<?php
+
+$r = new http\Env\Response;
+
+ob_start($r);
+echo "bar";
+ob_end_flush();
+
+$b = $r->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