@@ -114,37 +114,50 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
114
114
return NULL ;
115
115
}
116
116
117
- if (strpbrk (mode , "awx+" )) {
118
- php_stream_wrapper_log_error (wrapper , options TSRMLS_CC , "HTTP wrapper does not support writeable connections." );
119
- return NULL ;
120
- }
121
-
122
117
resource = php_url_parse (path );
123
118
if (resource == NULL ) {
124
119
return NULL ;
125
120
}
126
121
127
122
if (strncasecmp (resource -> scheme , "http" , sizeof ("http" )) && strncasecmp (resource -> scheme , "https" , sizeof ("https" ))) {
128
- php_url_free (resource );
129
- return php_stream_open_wrapper_ex (path , mode , ENFORCE_SAFE_MODE | REPORT_ERRORS , NULL , context );
130
- }
131
-
132
- use_ssl = resource -> scheme && (strlen (resource -> scheme ) > 4 ) && resource -> scheme [4 ] == 's' ;
133
- /* choose default ports */
134
- if (use_ssl && resource -> port == 0 )
135
- resource -> port = 443 ;
136
- else if (resource -> port == 0 )
137
- resource -> port = 80 ;
138
-
139
- if (context && !use_ssl &&
140
- php_stream_context_get_option (context , "http" , "proxy" , & tmpzval ) == SUCCESS &&
141
- Z_TYPE_PP (tmpzval ) == IS_STRING &&
142
- Z_STRLEN_PP (tmpzval ) > 0 ) {
143
- /* Don't use proxy server for SSL resources */
123
+ if (!context ||
124
+ php_stream_context_get_option (context , wrapper -> wops -> label , "proxy" , & tmpzval ) == FAILURE ||
125
+ Z_TYPE_PP (tmpzval ) != IS_STRING ||
126
+ Z_STRLEN_PP (tmpzval ) <= 0 ) {
127
+ php_url_free (resource );
128
+ return php_stream_open_wrapper_ex (path , mode , ENFORCE_SAFE_MODE | REPORT_ERRORS , NULL , context );
129
+ }
130
+ /* Called from a non-http wrapper with http proxying requested (i.e. ftp) */
131
+ request_fulluri = 1 ;
132
+ use_ssl = 0 ;
133
+
144
134
transport_len = Z_STRLEN_PP (tmpzval );
145
135
transport_string = estrndup (Z_STRVAL_PP (tmpzval ), Z_STRLEN_PP (tmpzval ));
146
136
} else {
147
- transport_len = spprintf (& transport_string , 0 , "%s://%s:%d" , use_ssl ? "ssl" : "tcp" , resource -> host , resource -> port );
137
+ /* Normal http request (possibly with proxy) */
138
+
139
+ if (strpbrk (mode , "awx+" )) {
140
+ php_stream_wrapper_log_error (wrapper , options TSRMLS_CC , "HTTP wrapper does not support writeable connections." );
141
+ return NULL ;
142
+ }
143
+
144
+ use_ssl = resource -> scheme && (strlen (resource -> scheme ) > 4 ) && resource -> scheme [4 ] == 's' ;
145
+ /* choose default ports */
146
+ if (use_ssl && resource -> port == 0 )
147
+ resource -> port = 443 ;
148
+ else if (resource -> port == 0 )
149
+ resource -> port = 80 ;
150
+
151
+ if (context && !use_ssl &&
152
+ php_stream_context_get_option (context , wrapper -> wops -> label , "proxy" , & tmpzval ) == SUCCESS &&
153
+ Z_TYPE_PP (tmpzval ) == IS_STRING &&
154
+ Z_STRLEN_PP (tmpzval ) > 0 ) {
155
+ /* Don't use proxy server for SSL resources */
156
+ transport_len = Z_STRLEN_PP (tmpzval );
157
+ transport_string = estrndup (Z_STRVAL_PP (tmpzval ), Z_STRLEN_PP (tmpzval ));
158
+ } else {
159
+ transport_len = spprintf (& transport_string , 0 , "%s://%s:%d" , use_ssl ? "ssl" : "tcp" , resource -> host , resource -> port );
160
+ }
148
161
}
149
162
150
163
stream = php_stream_xport_create (transport_string , transport_len , options ,
@@ -192,7 +205,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
192
205
}
193
206
194
207
/* Should we send the entire path in the request line, default to no. */
195
- if (context &&
208
+ if (!request_fulluri &&
209
+ context &&
196
210
php_stream_context_get_option (context , "http" , "request_fulluri" , & tmpzval ) == SUCCESS ) {
197
211
(* tmpzval )-> refcount ++ ;
198
212
SEPARATE_ZVAL (tmpzval );
@@ -292,7 +306,8 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
292
306
293
307
/* Send Host: header so name-based virtual hosts work */
294
308
if ((have_header & HTTP_HEADER_HOST ) == 0 ) {
295
- if ((use_ssl && resource -> port != 443 ) || (!use_ssl && resource -> port != 80 )) {
309
+ if ((use_ssl && resource -> port != 443 && resource -> port != 0 ) ||
310
+ (!use_ssl && resource -> port != 80 && resource -> port != 0 )) {
296
311
if (snprintf (scratch , scratch_len , "Host: %s:%i\r\n" , resource -> host , resource -> port ) > 0 )
297
312
php_stream_write (stream , scratch , strlen (scratch ));
298
313
} else {
@@ -525,7 +540,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
525
540
} else {
526
541
strlcpy (new_path , location , sizeof (new_path ));
527
542
}
528
- stream = php_stream_url_wrap_http_ex (NULL , new_path , mode , options , opened_path , context , -- redirect_max , 0 STREAMS_CC TSRMLS_CC );
543
+ stream = php_stream_url_wrap_http_ex (wrapper , new_path , mode , options , opened_path , context , -- redirect_max , 0 STREAMS_CC TSRMLS_CC );
529
544
if (stream && stream -> wrapperdata ) {
530
545
entryp = & entry ;
531
546
MAKE_STD_ZVAL (entry );
@@ -594,7 +609,7 @@ static php_stream_wrapper_ops http_stream_wops = {
594
609
php_stream_http_stream_stat ,
595
610
NULL , /* stat_url */
596
611
NULL , /* opendir */
597
- "HTTP " ,
612
+ "http " ,
598
613
NULL , /* unlink */
599
614
NULL , /* rename */
600
615
NULL , /* mkdir */
0 commit comments