- ensure proper message deallocation
authorMichael Wallner <mike@php.net>
Wed, 2 Nov 2005 16:32:01 +0000 (16:32 +0000)
committerMichael Wallner <mike@php.net>
Wed, 2 Nov 2005 16:32:01 +0000 (16:32 +0000)
http_api.c
http_message_api.c
php_http_std_defs.h
tests/HttpMessage_001.phpt
tests/HttpRequest_003.phpt

index 55f5e886ef15c4ae7a93ffda1b6a6b99707cb30a..8030c0f5d358df3f1bb5360d3cb57d6e3b7969a4 100644 (file)
@@ -249,13 +249,12 @@ void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC)
 /* {{{ STATUS http_exit(int, char*, char*) */
 STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC)
 {
-       if (status || send_header) {
-               if (SUCCESS != http_send_status_header(status, send_header ? header : NULL)) {
-                       http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : "");
-                       STR_FREE(header);
-                       STR_FREE(body);
-                       return FAILURE;
-               }
+       if (    (send_header && (SUCCESS != http_send_status_header(status, header))) ||
+                       (!send_header && status && (SUCCESS != http_send_status(status)))) {
+               http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : "");
+               STR_FREE(header);
+               STR_FREE(body);
+               return FAILURE;
        }
        
        if (php_header(TSRMLS_C) && body) {
index 6dd20673b081addab2c92fa72902d6cfa93b7ce1..7fe5aecb73d6a7f96aa8188a7c004e1b058f1d0c 100644 (file)
@@ -259,7 +259,7 @@ PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char
 #      endif /* HTTP_HAVE_ZLIB */
                        }
                        
-                       if (decoded && decoded_len) {
+                       if (decoded) {
                                zval *len;
                                char *tmp;
                                int tmp_len;
index 896048537a49bac390ed8b126bab22297a503700..40dc8c769e1b0ec00ca1b6e7364652697513de85 100644 (file)
@@ -66,17 +66,17 @@ typedef int STATUS;
        RETVAL_OBJECT(o); \
        return
 #define RETVAL_OBJVAL(ov) \
-       ZVAL_OBJVAL(return_value, ov)
+       ZVAL_OBJVAL(return_value, ov) \
+       if (Z_OBJ_HT_P(return_value)->add_ref) { \
+               Z_OBJ_HT_P(return_value)->add_ref(return_value TSRMLS_CC); \
+       }
 #define RETURN_OBJVAL(ov) \
        RETVAL_OBJVAL(ov); \
        return
 #define ZVAL_OBJVAL(zv, ov) \
        (zv)->type = IS_OBJECT; \
-       (zv)->value.obj = (ov); \
-       if (Z_OBJ_HT_P(zv)->add_ref) { \
-               Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \
-       }
-
+       (zv)->value.obj = (ov);
+       
 /* function accepts no args */
 #define NO_ARGS \
        if (ZEND_NUM_ARGS()) { \
index eda359c487333bb00bcdf219a3964789e272e7a3..1ceda68e24748ef9684d2ccaa2bf1db88cb98e3d 100644 (file)
@@ -12,7 +12,7 @@ $m = new HttpMessage(
        "HTTP/1.1 301\r\n".
        "Location: /anywhere\r\n".
        "HTTP/1.1 302\r\n".
-       "Location: /somwhere\r\n".
+       "Location: /somewhere\r\n".
        "HTTP/1.1 206\r\n".
        "Content-Range: bytes=2-3\r\n".
        "Transfer-Encoding: chunked\r\n".
@@ -23,30 +23,36 @@ $m = new HttpMessage(
 );
 
 var_dump($m->getBody());
-var_dump($m->toString(true));
 var_dump(HttpMessage::fromString($m->toString(true))->toString(true));
+do {
+       var_dump($m->toString());
+} while ($m = $m->getParentMessage());
+
+echo "Done\n";
 ?>
 --EXPECTF--
 %sTEST
 string(1) "X"
-string(134) "HTTP/1.1 301
+string(135) "HTTP/1.1 301
 Location: /anywhere
 HTTP/1.1 302
-Location: /somwhere
+Location: /somewhere
 HTTP/1.1 206
 Content-Range: bytes=2-3
 Content-Length: 1
 
 X
 "
-string(134) "HTTP/1.1 301
-Location: /anywhere
-HTTP/1.1 302
-Location: /somwhere
-HTTP/1.1 206
+string(64) "HTTP/1.1 206
 Content-Range: bytes=2-3
 Content-Length: 1
 
 X
 "
-
+string(36) "HTTP/1.1 302
+Location: /somewhere
+"
+string(35) "HTTP/1.1 301
+Location: /anywhere
+"
+Done
index d352b189b1d1289bbc4f763fef2ff70c92cfd1e4..bed6735263b4031c89820bb27497fdf4487c493e 100644 (file)
@@ -13,8 +13,13 @@ echo "-TEST\n";
 $r = new HttpRequest('https://ssl.arweb.info/iworks/data.txt');
 $r->send();
 var_dump($r->getResponseBody());
+var_dump(is_object($r->getResponseMessage()));
+var_dump(is_object($r->getResponseMessage()));
+var_dump(is_object($r->getResponseMessage()));
 ?>
 --EXPECTF--
 %sTEST
 string(10) "1234567890"
-
+bool(true)
+bool(true)
+bool(true)