@@ -107,9 +107,10 @@ static inline void strip_header(char *header_bag, char *lc_header_bag,
107
107
}
108
108
}
109
109
110
- php_stream * php_stream_url_wrap_http_ex (php_stream_wrapper * wrapper ,
110
+ static php_stream * php_stream_url_wrap_http_ex (php_stream_wrapper * wrapper ,
111
111
const char * path , const char * mode , int options , zend_string * * opened_path ,
112
- php_stream_context * context , int redirect_max , int flags STREAMS_DC ) /* {{{ */
112
+ php_stream_context * context , int redirect_max , int flags ,
113
+ zval * response_header STREAMS_DC ) /* {{{ */
113
114
{
114
115
php_stream * stream = NULL ;
115
116
php_url * resource = NULL ;
@@ -119,7 +120,6 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
119
120
char * ua_str = NULL ;
120
121
zval * ua_zval = NULL , * tmpzval = NULL , ssl_proxy_peer_name ;
121
122
char location [HTTP_HEADER_BLOCK_SIZE ];
122
- zval response_header ;
123
123
int reqok = 0 ;
124
124
char * http_header_line = NULL ;
125
125
char tmp_line [128 ];
@@ -137,11 +137,9 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
137
137
zend_bool follow_location = 1 ;
138
138
php_stream_filter * transfer_encoding = NULL ;
139
139
int response_code ;
140
- zend_array * symbol_table ;
141
140
smart_str req_buf = {0 };
142
141
zend_bool custom_request_method ;
143
142
144
- ZVAL_UNDEF (& response_header );
145
143
tmp_line [0 ] = '\0' ;
146
144
147
145
if (redirect_max < 1 ) {
@@ -659,22 +657,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
659
657
660
658
location [0 ] = '\0' ;
661
659
662
- symbol_table = zend_rebuild_symbol_table ();
663
-
664
- if (header_init ) {
665
- zval ztmp ;
666
- array_init (& ztmp );
667
- zend_set_local_var_str ("http_response_header" , sizeof ("http_response_header" )- 1 , & ztmp , 0 );
668
- }
669
-
670
- {
671
- zval * response_header_ptr = zend_hash_str_find_ind (symbol_table , "http_response_header" , sizeof ("http_response_header" )- 1 );
672
- if (!response_header_ptr || Z_TYPE_P (response_header_ptr ) != IS_ARRAY ) {
673
- ZVAL_UNDEF (& response_header );
674
- goto out ;
675
- } else {
676
- ZVAL_COPY (& response_header , response_header_ptr );
677
- }
660
+ if (Z_ISUNDEF_P (response_header )) {
661
+ array_init (response_header );
678
662
}
679
663
680
664
if (!php_stream_eof (stream )) {
@@ -741,7 +725,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
741
725
}
742
726
}
743
727
ZVAL_STRINGL (& http_response , tmp_line , tmp_line_len );
744
- zend_hash_next_index_insert (Z_ARRVAL (response_header ), & http_response );
728
+ zend_hash_next_index_insert (Z_ARRVAL_P (response_header ), & http_response );
745
729
}
746
730
} else {
747
731
php_stream_wrapper_log_error (wrapper , options , "HTTP request failed, unexpected end of socket!" );
@@ -840,7 +824,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
840
824
{
841
825
zval http_header ;
842
826
ZVAL_STRINGL (& http_header , http_header_line , http_header_line_length );
843
- zend_hash_next_index_insert (Z_ARRVAL (response_header ), & http_header );
827
+ zend_hash_next_index_insert (Z_ARRVAL_P (response_header ), & http_header );
844
828
}
845
829
} else {
846
830
break ;
@@ -930,7 +914,9 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
930
914
CHECK_FOR_CNTRL_CHARS (resource -> pass )
931
915
CHECK_FOR_CNTRL_CHARS (resource -> path )
932
916
}
933
- stream = php_stream_url_wrap_http_ex (wrapper , new_path , mode , options , opened_path , context , -- redirect_max , HTTP_WRAPPER_REDIRECTED STREAMS_CC );
917
+ stream = php_stream_url_wrap_http_ex (
918
+ wrapper , new_path , mode , options , opened_path , context ,
919
+ -- redirect_max , HTTP_WRAPPER_REDIRECTED , response_header STREAMS_CC );
934
920
} else {
935
921
php_stream_wrapper_log_error (wrapper , options , "HTTP request failed! %s" , tmp_line );
936
922
}
@@ -949,7 +935,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
949
935
950
936
if (stream ) {
951
937
if (header_init ) {
952
- ZVAL_COPY (& stream -> wrapperdata , & response_header );
938
+ ZVAL_COPY (& stream -> wrapperdata , response_header );
953
939
}
954
940
php_stream_notify_progress_init (context , 0 , file_size );
955
941
@@ -976,15 +962,28 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
976
962
}
977
963
}
978
964
979
- zval_ptr_dtor (& response_header );
980
-
981
965
return stream ;
982
966
}
983
967
/* }}} */
984
968
985
969
php_stream * php_stream_url_wrap_http (php_stream_wrapper * wrapper , const char * path , const char * mode , int options , zend_string * * opened_path , php_stream_context * context STREAMS_DC ) /* {{{ */
986
970
{
987
- return php_stream_url_wrap_http_ex (wrapper , path , mode , options , opened_path , context , PHP_URL_REDIRECT_MAX , HTTP_WRAPPER_HEADER_INIT STREAMS_CC );
971
+ php_stream * stream ;
972
+ zval headers ;
973
+ ZVAL_UNDEF (& headers );
974
+
975
+ stream = php_stream_url_wrap_http_ex (
976
+ wrapper , path , mode , options , opened_path , context ,
977
+ PHP_URL_REDIRECT_MAX , HTTP_WRAPPER_HEADER_INIT , & headers STREAMS_CC );
978
+
979
+ if (!Z_ISUNDEF (headers )) {
980
+ if (FAILURE == zend_set_local_var_str (
981
+ "http_response_header" , sizeof ("http_response_header" )- 1 , & headers , 0 )) {
982
+ zval_ptr_dtor (& headers );
983
+ }
984
+ }
985
+
986
+ return stream ;
988
987
}
989
988
/* }}} */
990
989
0 commit comments