Skip to content

Commit 66b88c9

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Fixed bug #55438 (Curlwapper is not sending http header randomly)
2 parents 59692de + c46e1cd commit 66b88c9

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ PHP NEWS
1313
. Update list of common mime types. Added webm, ogv, ogg. (Lars,
1414
pascalc at gmail dot com)
1515

16+
- cURL extension:
17+
. Fixed bug #55438 (Curlwapper is not sending http header randomly).
18+
(phpnet@lostreality.org, Pierrick)
19+
1620
?? ??? 2012, PHP 5.4.10
1721

1822
- Core:

ext/curl/php_curl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ typedef struct {
181181
CURLMcode mcode;
182182
int pending;
183183
zval *headers;
184+
struct curl_slist *headers_slist; /* holds custom headers sent out in the request */
184185
} php_curl_stream;
185186

186187

ext/curl/streams.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ static int php_curl_stream_close(php_stream *stream, int close_handle TSRMLS_DC)
218218
curl_easy_cleanup(curlstream->curl);
219219
curl_multi_cleanup(curlstream->multi);
220220

221+
if (curlstream->headers_slist) {
222+
curl_slist_free_all(curlstream->headers_slist);
223+
}
224+
221225
/* we are not closing curlstream->readbuf here, because we export
222226
* it as a zval with the wrapperdata - the engine will garbage collect it */
223227

@@ -268,7 +272,6 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
268272
php_stream *stream;
269273
php_curl_stream *curlstream;
270274
zval *tmp, **ctx_opt = NULL;
271-
struct curl_slist *slist = NULL;
272275

273276
curlstream = emalloc(sizeof(php_curl_stream));
274277
memset(curlstream, 0, sizeof(php_curl_stream));
@@ -279,6 +282,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
279282
curlstream->curl = curl_easy_init();
280283
curlstream->multi = curl_multi_init();
281284
curlstream->pending = 1;
285+
curlstream->headers_slist = NULL;
282286

283287
/* if opening for an include statement, ensure that the local storage will
284288
* have a FILE* associated with it.
@@ -351,7 +355,7 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
351355
zend_hash_move_forward_ex(Z_ARRVAL_PP(ctx_opt), &pos)
352356
) {
353357
if (Z_TYPE_PP(header) == IS_STRING) {
354-
slist = curl_slist_append(slist, Z_STRVAL_PP(header));
358+
curlstream->headers_slist = curl_slist_append(curlstream->headers_slist, Z_STRVAL_PP(header));
355359
}
356360
}
357361
} 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_stream_wrapper *wrapper, char *filename,
361365
p = php_strtok_r(copy_ctx_opt, "\r\n", &token);
362366
while (p) {
363367
trimmed = php_trim(p, strlen(p), NULL, 0, NULL, 3 TSRMLS_CC);
364-
slist = curl_slist_append(slist, trimmed);
368+
curlstream->headers_slist = curl_slist_append(curlstream->headers_slist, trimmed);
365369
efree(trimmed);
366370
p = php_strtok_r(NULL, "\r\n", &token);
367371
}
368372
efree(copy_ctx_opt);
369373
}
370-
if (slist) {
371-
curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, slist);
374+
if (curlstream->headers_slist) {
375+
curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, curlstream->headers_slist);
372376
}
373377
}
374378
if (SUCCESS == php_stream_context_get_option(context, "http", "method", &ctx_opt) && Z_TYPE_PP(ctx_opt) == IS_STRING) {
@@ -500,18 +504,10 @@ php_stream *php_curl_stream_opener(php_stream_wrapper *wrapper, char *filename,
500504
}
501505
}
502506

503-
/* context headers are not needed anymore */
504-
if (slist) {
505-
curl_easy_setopt(curlstream->curl, CURLOPT_HTTPHEADER, NULL);
506-
curl_slist_free_all(slist);
507-
}
508507
return stream;
509508

510509
exit_fail:
511510
php_stream_close(stream);
512-
if (slist) {
513-
curl_slist_free_all(slist);
514-
}
515511
return NULL;
516512
}
517513

0 commit comments

Comments
 (0)