@@ -113,6 +113,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
113
113
int redirected = ((flags & HTTP_WRAPPER_REDIRECTED ) != 0 );
114
114
int follow_location = 1 ;
115
115
php_stream_filter * transfer_encoding = NULL ;
116
+ int response_code ;
116
117
117
118
tmp_line [0 ] = '\0' ;
118
119
@@ -657,7 +658,6 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
657
658
658
659
if (php_stream_get_line (stream , tmp_line , sizeof (tmp_line ) - 1 , & tmp_line_len ) != NULL ) {
659
660
zval * http_response ;
660
- int response_code ;
661
661
662
662
if (tmp_line_len > 9 ) {
663
663
response_code = atoi (tmp_line + 9 );
@@ -731,7 +731,9 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
731
731
http_header_line [http_header_line_length ] = '\0' ;
732
732
733
733
if (!strncasecmp (http_header_line , "Location: " , 10 )) {
734
- if (context && php_stream_context_get_option (context , "http" , "follow_location" , & tmpzval ) == SUCCESS ) {
734
+ /* we only care about Location for 300, 301, 302, 303 and 307 */
735
+ /* see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.1 */
736
+ if ((response_code >= 300 && response_code < 304 || 307 == response_code ) && context && php_stream_context_get_option (context , "http" , "follow_location" , & tmpzval ) == SUCCESS ) {
735
737
SEPARATE_ZVAL (tmpzval );
736
738
convert_to_long_ex (tmpzval );
737
739
follow_location = Z_LVAL_PP (tmpzval );
0 commit comments