update response headers
authorMichael Wallner <mike@php.net>
Tue, 3 Feb 2015 19:09:38 +0000 (20:09 +0100)
committerMichael Wallner <mike@php.net>
Tue, 3 Feb 2015 19:09:38 +0000 (20:09 +0100)
php_http_client_curl.c
php_http_message.c

index 02c72ac5b5e4378e0373316639d2fb76b15959ad..566e523b9154b67803abb8a11d67d58818820d91 100644 (file)
@@ -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);
index ffa9c3909a8e73787d73b77216f24433bca4f220..8a7e564a761990743270c2e7c736de49cc2471ce 100644 (file)
@@ -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;