Skip to content

Commit 738346f

Browse files
committed
MFH: Fixed previous fix
1 parent cbf2df4 commit 738346f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ext/standard/http_fopen_wrapper.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181
#define HTTP_HEADER_CONTENT_LENGTH 16
8282
#define HTTP_HEADER_TYPE 32
8383

84-
php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context, int redirect_max, int header_init STREAMS_DC TSRMLS_DC)
84+
#define HTTP_WRAPPER_HEADER_INIT 1
85+
#define HTTP_WRAPPER_REDIRECTED 2
86+
87+
php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context, int redirect_max, int flags STREAMS_DC TSRMLS_DC)
8588
{
8689
php_stream *stream = NULL;
8790
php_url *resource = NULL;
@@ -106,6 +109,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
106109
int protocol_version_len = 3; /* Default: "1.0" */
107110
struct timeval timeout;
108111
char *user_headers = NULL;
112+
int header_init = ((flags & HTTP_WRAPPER_HEADER_INIT) != 0);
113+
int redirected = ((flags & HTTP_WRAPPER_REDIRECTED) != 0);
109114

110115
tmp_line[0] = '\0';
111116

@@ -254,7 +259,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
254259
if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) > 0) {
255260
/* As per the RFC, automatically redirected requests MUST NOT use other methods than
256261
* GET and HEAD unless it can be confirmed by the user */
257-
if (redirect_max == PHP_URL_REDIRECT_MAX
262+
if (!redirected
258263
|| (Z_STRLEN_PP(tmpzval) == 3 && memcmp("GET", Z_STRVAL_PP(tmpzval), 3) == 0)
259264
|| (Z_STRLEN_PP(tmpzval) == 4 && memcmp("HEAD",Z_STRVAL_PP(tmpzval), 4) == 0)
260265
) {
@@ -696,7 +701,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
696701
CHECK_FOR_CNTRL_CHARS(resource->pass)
697702
CHECK_FOR_CNTRL_CHARS(resource->path)
698703
}
699-
stream = php_stream_url_wrap_http_ex(wrapper, new_path, mode, options, opened_path, context, --redirect_max, 0 STREAMS_CC TSRMLS_CC);
704+
stream = php_stream_url_wrap_http_ex(wrapper, new_path, mode, options, opened_path, context, --redirect_max, HTTP_WRAPPER_REDIRECTED STREAMS_CC TSRMLS_CC);
700705
} else {
701706
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP request failed! %s", tmp_line);
702707
}
@@ -742,7 +747,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
742747

743748
php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
744749
{
745-
return php_stream_url_wrap_http_ex(wrapper, path, mode, options, opened_path, context, PHP_URL_REDIRECT_MAX, 1 STREAMS_CC TSRMLS_CC);
750+
return php_stream_url_wrap_http_ex(wrapper, path, mode, options, opened_path, context, PHP_URL_REDIRECT_MAX, HTTP_WRAPPER_HEADER_INIT STREAMS_CC TSRMLS_CC);
746751
}
747752

748753
static int php_stream_http_stream_stat(php_stream_wrapper *wrapper,

0 commit comments

Comments
 (0)