diff options
| author | Ilia Alshanetsky <iliaa@php.net> | 2006-09-25 16:00:43 +0000 |
|---|---|---|
| committer | Ilia Alshanetsky <iliaa@php.net> | 2006-09-25 16:00:43 +0000 |
| commit | cc0d254e4f319279629c80530325d7c12dee1ec7 (patch) | |
| tree | 35fd3790dee9df1dc4d2e72c1a295f9c893a72ac /ext/standard/url.c | |
| parent | ccc25cc3eb46c87d8f83f73c66a503e9f29fad07 (diff) | |
| download | php-git-cc0d254e4f319279629c80530325d7c12dee1ec7.tar.gz | |
Fixed bug #38891 (get_headers() do not work with curl-wrappers).
Diffstat (limited to 'ext/standard/url.c')
| -rw-r--r-- | ext/standard/url.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/ext/standard/url.c b/ext/standard/url.c index 43846bd037..77e9da11d8 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -661,8 +661,9 @@ PHP_FUNCTION(get_headers) int url_len; php_stream_context *context; php_stream *stream; - zval **prev_val, **hdr = NULL; + zval **prev_val, **hdr = NULL, **h; HashPosition pos; + HashTable *hashT; long format = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &format) == FAILURE) { @@ -676,10 +677,22 @@ PHP_FUNCTION(get_headers) array_init(return_value); - zend_hash_internal_pointer_reset_ex(HASH_OF(stream->wrapperdata), &pos); - while (zend_hash_get_current_data_ex(HASH_OF(stream->wrapperdata), (void**)&hdr, &pos) != FAILURE) { + /* check for curl-wrappers that provide headers via a special "headers" element */ + if (zend_hash_find(HASH_OF(stream->wrapperdata), "headers", sizeof("headers"), (void **)&h) != FAILURE && Z_TYPE_PP(h) == IS_ARRAY) { + /* curl-wrappers don't load data until the 1st read */ + if (!Z_ARRVAL_PP(h)->nNumOfElements) { + php_stream_getc(stream); + } + zend_hash_find(HASH_OF(stream->wrapperdata), "headers", sizeof("headers"), (void **)&h); + hashT = Z_ARRVAL_PP(h); + } else { + hashT = HASH_OF(stream->wrapperdata); + } + + zend_hash_internal_pointer_reset_ex(hashT, &pos); + while (zend_hash_get_current_data_ex(hashT, (void**)&hdr, &pos) != FAILURE) { if (!hdr || Z_TYPE_PP(hdr) != IS_STRING) { - zend_hash_move_forward_ex(HASH_OF(stream->wrapperdata), &pos); + zend_hash_move_forward_ex(hashT, &pos); continue; } if (!format) { @@ -709,7 +722,7 @@ no_name_header: goto no_name_header; } } - zend_hash_move_forward_ex(HASH_OF(stream->wrapperdata), &pos); + zend_hash_move_forward_ex(hashT, &pos); } php_stream_close(stream); |
