php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #55438
Patch curl-wrapper-header-fix revision 2012-12-19 04:24 UTC by phpnet at lostreality dot org

Patch curl-wrapper-header-fix for cURL related Bug #55438

Patch version 2012-12-19 04:24 UTC

Return to Bug #55438 | Download this patch
Patch Revisions:

Developer: phpnet@lostreality.org

diff -up ext/curl/php_curl.orig ext/curl/php_curl.h
--- ext/curl/php_curl.orig      2012-12-18 22:02:20.000000000 -0600
+++ ext/curl/php_curl.h 2012-12-18 22:03:53.000000000 -0600
@@ -181,6 +181,7 @@ typedef struct {
        CURLMcode mcode;
        int pending;
        zval *headers;
+       struct curl_slist *slist; /* holds custom headers sent out in the request */
 } php_curl_stream;


diff -up ext/curl/streams.orig ext/curl/streams.c
--- ext/curl/streams.orig       2012-12-18 21:59:18.000000000 -0600
+++ ext/curl/streams.c  2012-12-18 22:17:49.000000000 -0600
@@ -218,6 +218,11 @@ static int php_curl_stream_close(php_str
        curl_easy_cleanup(curlstream->curl);
        curl_multi_cleanup(curlstream->multi);

+       /* context headers are not needed anymore */
+       if (curlstream->slist) {
+               curl_slist_free_all(curlstream->slist);
+       }
+
        /* we are not closing curlstream->readbuf here, because we export
         * it as a zval with the wrapperdata - the engine will garbage collect it */

@@ -268,7 +273,6 @@ php_stream *php_curl_stream_opener(php_s
        php_stream *stream;
        php_curl_stream *curlstream;
        zval *tmp, **ctx_opt = NULL;
-       struct curl_slist *slist = NULL;

        curlstream = emalloc(sizeof(php_curl_stream));
        memset(curlstream, 0, sizeof(php_curl_stream));
@@ -351,7 +355,7 @@ php_stream *php_curl_stream_opener(php_s
                                        zend_hash_move_forward_ex(Z_ARRVAL_PP(ctx_opt), &pos)
                                ) {
                                        if (Z_TYPE_PP(header) == IS_STRING) {
-                                               slist = curl_slist_append(slist, Z_STRVAL_PP(header));
+                                               curlstream->slist = curl_slist_append(curlstream->slist, Z_STRVAL_PP(header));
                                        }
                                }
                        } else if (Z_TYPE_PP(ctx_opt) == IS_STRING && Z_STRLEN_PP(ctx_opt)) {
@@ -361,14 +365,14 @@ php_stream *php_curl_stream_opener(php_s
                                p = php_strtok_r(copy_ctx_opt, "\r\n", &token);
                                while (p) {
                                        trimmed = php_trim(p, strlen(p), NULL, 0, NULL, 3 TSRMLS_CC);
-                                       slist = curl_slist_append(slist, trimmed);
+                                       curlstream->slist = curl_slist_append(curlstream->slist, trimmed);
                                        efree(trimmed);
                                        p = php_strtok_r(NULL, "\r\n", &token);
                                }
                                efree(copy_ctx_opt);
                        }
-                       if (slist) {
-                               curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, slist);
+                       if (curlstream->slist) {
+                               curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, curlstream->slist);
                        }
                }
                if (SUCCESS == php_stream_context_get_option(context, "http", "method", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) {
@@ -500,17 +504,12 @@ php_stream *php_curl_stream_opener(php_s
                }
        }

-       /* context headers are not needed anymore */
-       if (slist) {
-               curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, NULL);
-               curl_slist_free_all(slist);
-       }
        return stream;

 exit_fail:
        php_stream_close(stream);
-       if (slist) {
-               curl_slist_free_all(slist);
+       if (curlstream->slist) {
+               curl_slist_free_all(curlstream->slist);
        }
        return NULL;
 }
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC