X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_message.c;h=b7b500b313bbea8b1308c194e14e1e653cc0b33c;hp=ffa9c3909a8e73787d73b77216f24433bca4f220;hb=refs%2Fheads%2Fv2.3.x;hpb=498493b4cb032edc2ec5b8baa51bebf70ad77d6a diff --git a/php_http_message.c b/php_http_message.c index ffa9c39..b7b500b 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -297,16 +297,14 @@ void php_http_message_update_headers(php_http_message_t *msg) if (php_http_message_body_stream(msg->body)->readfilters.head) { /* if a read stream filter is attached to the body the caller must also care for the headers */ + } else if ((h = php_http_message_header(msg, ZEND_STRL("Content-Range"), 0))) { + /* don't mess around with a Content-Range message */ + zval_ptr_dtor(&h); } else if ((size = php_http_message_body_size(msg->body))) { MAKE_STD_ZVAL(h); ZVAL_LONG(h, size); zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), &h, sizeof(zval *), NULL); - if ((h = php_http_message_header(msg, ZEND_STRL("Transfer-Encoding"), 0))) { - zend_hash_update(&msg->hdrs, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), (void *) &h, sizeof(zval *), NULL); - zend_hash_del(&msg->hdrs, "Transfer-Encoding", sizeof("Transfer-Encoding")); - } - if (msg->body->boundary) { char *str; size_t len; @@ -329,6 +327,7 @@ void php_http_message_update_headers(php_http_message_t *msg) zval_ptr_dtor(&h); if (Z_LVAL_P(h_cpy)) { + /* body->size == 0, so get rid of old Content-Length */ zend_hash_del(&msg->hdrs, "Content-Length", sizeof("Content-Length")); } zval_ptr_dtor(&h_cpy); @@ -1166,17 +1165,19 @@ static PHP_METHOD(HttpMessage, getHeader) if (!header_ce) { RETURN_ZVAL(header, 1, 1); } else if (instanceof_function(header_ce, php_http_header_class_entry TSRMLS_CC)) { + php_http_object_method_t cb; zval *header_name, **argv[2]; MAKE_STD_ZVAL(header_name); ZVAL_STRINGL(header_name, header_str, header_len, 1); - Z_ADDREF_P(header); argv[0] = &header_name; argv[1] = &header; object_init_ex(return_value, header_ce); - php_http_method_call(return_value, ZEND_STRL("__construct"), 2, argv, NULL TSRMLS_CC); + php_http_object_method_init(&cb, return_value, ZEND_STRL("__construct") TSRMLS_CC); + php_http_object_method_call(&cb, return_value, NULL, 2, argv TSRMLS_CC); + php_http_object_method_dtor(&cb); zval_ptr_dtor(&header_name); zval_ptr_dtor(&header); @@ -1676,6 +1677,16 @@ static PHP_METHOD(HttpMessage, toString) RETURN_EMPTY_STRING(); } +#ifdef ZTS +static size_t write_to_stream(void *s, const char *str, size_t len) +{ + TSRMLS_FETCH(); + return php_stream_write(s, str, len); +} +#else +# define write_to_stream (php_http_pass_callback_t)_php_stream_write +#endif + ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream, 0, 0, 1) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO(); @@ -1690,7 +1701,7 @@ static PHP_METHOD(HttpMessage, toStream) PHP_HTTP_MESSAGE_OBJECT_INIT(obj); php_stream_from_zval(s, &zstream); - php_http_message_to_callback(obj->message, (php_http_pass_callback_t) _php_stream_write, s); + php_http_message_to_callback(obj->message, write_to_stream, s); } }