From: Michael Wallner Date: Tue, 3 Feb 2015 19:09:38 +0000 (+0100) Subject: update response headers X-Git-Tag: RELEASE_2_3_0_RC1~68 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=91894f441698c7d430d9c1233700227dbee94f0d;p=m6w6%2Fext-http update response headers --- diff --git a/php_http_client_curl.c b/php_http_client_curl.c index 02c72ac..566e523 100644 --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@ -593,8 +593,9 @@ static int compare_queue(php_http_client_enqueue_t *e, void *handle) static php_http_message_t *php_http_curlm_responseparser(php_http_client_curl_handler_t *h TSRMLS_DC) { - php_http_message_t *response = NULL; + php_http_message_t *response; php_http_header_parser_t parser; + zval *zh; response = php_http_message_init(NULL, 0, h->response.body TSRMLS_CC); php_http_header_parser_init(&parser TSRMLS_CC); @@ -613,6 +614,22 @@ static php_http_message_t *php_http_curlm_responseparser(php_http_client_curl_ha } php_http_message_body_addref(h->response.body); + /* let's update the response headers */ + if ((zh = php_http_message_header(response, ZEND_STRL("Content-Length"), 1))) { + zend_hash_update(&response->hdrs, "X-Original-Content-Length", sizeof("X-Original-Content-Length"), &zh, sizeof(zval *), NULL); + } + if ((zh = php_http_message_header(response, ZEND_STRL("Transfer-Encoding"), 0))) { + zend_hash_update(&response->hdrs, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), (void *) &zh, sizeof(zval *), NULL); + zend_hash_del(&response->hdrs, "Transfer-Encoding", sizeof("Transfer-Encoding")); + } + if ((zh = php_http_message_header(response, ZEND_STRL("Content-Range"), 0))) { + zend_hash_update(&response->hdrs, "X-Original-Content-Range", sizeof("X-Original-Content-Range"), &zh, sizeof(zval *), NULL); + zend_hash_del(&response->hdrs, "Content-Range", sizeof("Content-Range")); + } + if ((zh = php_http_message_header(response, ZEND_STRL("Content-Encoding"), 0))) { + zend_hash_update(&response->hdrs, "X-Original-Content-Encoding", sizeof("X-Original-Content-Encoding"), &zh, sizeof(zval *), NULL); + zend_hash_del(&response->hdrs, "Content-Encoding", sizeof("Content-Encoding")); + } php_http_message_update_headers(response); return response; @@ -638,8 +655,10 @@ static void php_http_curlm_responsehandler(php_http_client_t *context) php_http_client_curl_handler_t *handler = enqueue->opaque; php_http_message_t *response = php_http_curlm_responseparser(handler TSRMLS_CC); - context->callback.response.func(context->callback.response.arg, context, &handler->queue, &response); - php_http_message_free(&response); + if (response) { + context->callback.response.func(context->callback.response.arg, context, &handler->queue, &response); + php_http_message_free(&response); + } } } } while (remaining); diff --git a/php_http_message.c b/php_http_message.c index ffa9c39..8a7e564 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -302,11 +302,6 @@ void php_http_message_update_headers(php_http_message_t *msg) 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;