@@ -264,28 +264,23 @@ private function onResponseRedirect(ResponseInterface $response, RequestInterfac
264264 */
265265 private function makeRedirectRequest (RequestInterface $ request , UriInterface $ location , $ statusCode )
266266 {
267- $ originalHost = $ request ->getUri ()->getHost ();
268- $ request = $ request ->withoutHeader ('Host ' )->withUri ($ location );
269-
270- if (!$ this ->isTemporaryOrPermanentRedirect ($ statusCode )) {
271- $ request = $ request
272- ->withoutHeader ('Content-Type ' )
273- ->withoutHeader ('Content-Length ' );
274- }
275267
276268 // Remove authorization if changing hostnames (but not if just changing ports or protocols).
269+ $ originalHost = $ request ->getUri ()->getHost ();
277270 if ($ location ->getHost () !== $ originalHost ) {
278271 $ request = $ request ->withoutHeader ('Authorization ' );
279272 }
280273
281- if ($ this -> isTemporaryOrPermanentRedirect ( $ statusCode) ) {
274+ if ($ statusCode === Response:: STATUS_TEMPORARY_REDIRECT || $ statusCode === Response:: STATUS_PERMANENT_REDIRECT ) {
282275 if ($ request ->getBody () instanceof ReadableStreamInterface) {
283276 throw new \RuntimeException ('Unable to redirect request with streaming body ' );
284277 }
285278 } else {
286- // naïve approach..
287- $ method = ($ request ->getMethod () === 'HEAD ' ) ? 'HEAD ' : 'GET ' ;
288- $ request = $ request ->withMethod ($ method )->withBody (new EmptyBodyStream ());
279+ $ request = $ request
280+ ->withMethod ($ request ->getMethod () === 'HEAD ' ? 'HEAD ' : 'GET ' )
281+ ->withoutHeader ('Content-Type ' )
282+ ->withoutHeader ('Content-Length ' )
283+ ->withBody (new EmptyBodyStream ());
289284 }
290285
291286 return $ request ;
@@ -311,14 +306,4 @@ private function progress($name, array $args = array())
311306 echo PHP_EOL ;
312307 }
313308
314- /**
315- * @param $statusCode
316- * @return bool
317- */
318- public function isTemporaryOrPermanentRedirect ($ statusCode )
319- {
320- return
321- $ statusCode === Response::STATUS_TEMPORARY_REDIRECT
322- || $ statusCode === Response::STATUS_PERMANENT_REDIRECT ;
323- }
324309}
0 commit comments