@@ -77,12 +77,12 @@ public function request(string $method, string $url, array $options = []): Respo
7777 $ options ['body ' ] = self ::getBodyAsString ($ options ['body ' ]);
7878
7979 if ('' !== $ options ['body ' ] && 'POST ' === $ method && !isset ($ options ['headers ' ]['content-type ' ])) {
80- $ options ['raw_headers ' ][] = 'content-type: application/x-www-form-urlencoded ' ;
80+ $ options ['request_headers ' ][] = 'content-type: application/x-www-form-urlencoded ' ;
8181 }
8282
8383 if ($ gzipEnabled = \extension_loaded ('zlib ' ) && !isset ($ options ['headers ' ]['accept-encoding ' ])) {
8484 // gzip is the most widely available algo, no need to deal with deflate
85- $ options ['raw_headers ' ][] = 'accept-encoding: gzip ' ;
85+ $ options ['request_headers ' ][] = 'accept-encoding: gzip ' ;
8686 }
8787
8888 if ($ options ['peer_fingerprint ' ]) {
@@ -94,7 +94,7 @@ public function request(string $method, string $url, array $options = []): Respo
9494 }
9595
9696 $ info = [
97- 'raw_headers ' => [],
97+ 'response_headers ' => [],
9898 'url ' => $ url ,
9999 'error ' => null ,
100100 'http_method ' => $ method ,
@@ -159,7 +159,7 @@ public function request(string $method, string $url, array $options = []): Respo
159159 [$ host , $ port , $ url ['authority ' ]] = self ::dnsResolve ($ url , $ this ->multi , $ info , $ onProgress );
160160
161161 if (!isset ($ options ['headers ' ]['host ' ])) {
162- $ options ['raw_headers ' ][] = 'host: ' .$ host .$ port ;
162+ $ options ['request_headers ' ][] = 'host: ' .$ host .$ port ;
163163 }
164164
165165 $ context = [
@@ -203,7 +203,7 @@ public function request(string $method, string $url, array $options = []): Respo
203203
204204 $ resolveRedirect = self ::createRedirectResolver ($ options , $ host , $ proxy , $ noProxy , $ info , $ onProgress );
205205 $ context = stream_context_create ($ context , ['notification ' => $ notification ]);
206- self ::configureHeadersAndProxy ($ context , $ host , $ options ['raw_headers ' ], $ proxy , $ noProxy );
206+ self ::configureHeadersAndProxy ($ context , $ host , $ options ['request_headers ' ], $ proxy , $ noProxy );
207207
208208 return new NativeResponse ($ this ->multi , $ context , implode ('' , $ url ), $ options , $ gzipEnabled , $ info , $ resolveRedirect , $ onProgress );
209209 }
@@ -326,12 +326,12 @@ private static function createRedirectResolver(array $options, string $host, ?ar
326326 $ redirectHeaders = [];
327327 if (0 < $ maxRedirects = $ options ['max_redirects ' ]) {
328328 $ redirectHeaders = ['host ' => $ host ];
329- $ redirectHeaders ['with_auth ' ] = $ redirectHeaders ['no_auth ' ] = array_filter ($ options ['raw_headers ' ], static function ($ h ) {
329+ $ redirectHeaders ['with_auth ' ] = $ redirectHeaders ['no_auth ' ] = array_filter ($ options ['request_headers ' ], static function ($ h ) {
330330 return 0 !== stripos ($ h , 'Host: ' );
331331 });
332332
333333 if (isset ($ options ['headers ' ]['authorization ' ]) || isset ($ options ['headers ' ]['cookie ' ])) {
334- $ redirectHeaders ['no_auth ' ] = array_filter ($ options ['raw_headers ' ], static function ($ h ) {
334+ $ redirectHeaders ['no_auth ' ] = array_filter ($ options ['request_headers ' ], static function ($ h ) {
335335 return 0 !== stripos ($ h , 'Authorization: ' ) && 0 !== stripos ($ h , 'Cookie: ' );
336336 });
337337 }
@@ -376,46 +376,46 @@ private static function createRedirectResolver(array $options, string $host, ?ar
376376
377377 if (false !== (parse_url ($ location , PHP_URL_HOST ) ?? false )) {
378378 // Authorization and Cookie headers MUST NOT follow except for the initial host name
379- $ rawHeaders = $ redirectHeaders ['host ' ] === $ host ? $ redirectHeaders ['with_auth ' ] : $ redirectHeaders ['no_auth ' ];
380- $ rawHeaders [] = 'host: ' .$ host .$ port ;
381- self ::configureHeadersAndProxy ($ context , $ host , $ rawHeaders , $ proxy , $ noProxy );
379+ $ requestHeaders = $ redirectHeaders ['host ' ] === $ host ? $ redirectHeaders ['with_auth ' ] : $ redirectHeaders ['no_auth ' ];
380+ $ requestHeaders [] = 'host: ' .$ host .$ port ;
381+ self ::configureHeadersAndProxy ($ context , $ host , $ requestHeaders , $ proxy , $ noProxy );
382382 }
383383
384384 return implode ('' , $ url );
385385 };
386386 }
387387
388- private static function configureHeadersAndProxy ($ context , string $ host , array $ rawHeaders , ?array $ proxy , array $ noProxy )
388+ private static function configureHeadersAndProxy ($ context , string $ host , array $ requestHeaders , ?array $ proxy , array $ noProxy )
389389 {
390390 if (null === $ proxy ) {
391- return stream_context_set_option ($ context , 'http ' , 'header ' , $ rawHeaders );
391+ return stream_context_set_option ($ context , 'http ' , 'header ' , $ requestHeaders );
392392 }
393393
394394 // Matching "no_proxy" should follow the behavior of curl
395395
396396 foreach ($ noProxy as $ rule ) {
397397 if ('* ' === $ rule ) {
398- return stream_context_set_option ($ context , 'http ' , 'header ' , $ rawHeaders );
398+ return stream_context_set_option ($ context , 'http ' , 'header ' , $ requestHeaders );
399399 }
400400
401401 if ($ host === $ rule ) {
402- return stream_context_set_option ($ context , 'http ' , 'header ' , $ rawHeaders );
402+ return stream_context_set_option ($ context , 'http ' , 'header ' , $ requestHeaders );
403403 }
404404
405405 $ rule = '. ' .ltrim ($ rule , '. ' );
406406
407407 if (substr ($ host , -\strlen ($ rule )) === $ rule ) {
408- return stream_context_set_option ($ context , 'http ' , 'header ' , $ rawHeaders );
408+ return stream_context_set_option ($ context , 'http ' , 'header ' , $ requestHeaders );
409409 }
410410 }
411411
412412 stream_context_set_option ($ context , 'http ' , 'proxy ' , $ proxy ['url ' ]);
413413 stream_context_set_option ($ context , 'http ' , 'request_fulluri ' , true );
414414
415415 if (null !== $ proxy ['auth ' ]) {
416- $ rawHeaders [] = 'Proxy-Authorization: ' .$ proxy ['auth ' ];
416+ $ requestHeaders [] = 'Proxy-Authorization: ' .$ proxy ['auth ' ];
417417 }
418418
419- return stream_context_set_option ($ context , 'http ' , 'header ' , $ rawHeaders );
419+ return stream_context_set_option ($ context , 'http ' , 'header ' , $ requestHeaders );
420420 }
421421}
0 commit comments