@@ -401,8 +401,9 @@ internal class _HTTPURLProtocol: _NativeProtocol {
401401 easyHandle. timeoutTimer = _TimeoutSource ( queue: task. workQueue, milliseconds: timeoutInterval, handler: timeoutHandler)
402402 easyHandle. set ( automaticBodyDecompression: true )
403403 easyHandle. set ( requestMethod: request. httpMethod ?? " GET " )
404- // Always set the status as it may change if a HEAD is converted to a GET.
405- easyHandle. set ( noBody: request. httpMethod == " HEAD " )
404+ if request. httpMethod == " HEAD " {
405+ easyHandle. set ( noBody: true )
406+ }
406407 }
407408
408409 /// What action to take
@@ -590,7 +591,7 @@ internal extension _HTTPURLProtocol {
590591 // For now, we'll notify the delegate, but won't pause the transfer,
591592 // and we'll disregard the completion handler:
592593 switch response. statusCode {
593- case 301 , 302 , 303 , 305 ... 308 :
594+ case 301 , 302 , 303 , 307 :
594595 break
595596 default :
596597 self . client? . urlProtocol ( self , didReceive: response, cacheStoragePolicy: . notAllowed)
@@ -618,26 +619,19 @@ internal extension _HTTPURLProtocol {
618619 return nil
619620 }
620621
621- let method = fromRequest. httpMethod ?? " GET "
622622 // Check for a redirect:
623623 switch response. statusCode {
624- case 301 , 302 :
625- // Change "POST" into "GET" but leave other methods unchanged:
626- let newMethod = ( method == " POST " ) ? " GET " : method
627- return ( newMethod, targetURL)
628-
629- case 303 :
630- return ( " GET " , targetURL)
631-
632- case 305 ... 308 :
633- // Re-use existing method:
634- return ( method, targetURL)
635-
636- default :
637- return nil
624+ //TODO: Should we do this for 300 "Multiple Choices", too?
625+ case 301 , 302 , 303 :
626+ // Change into "GET":
627+ return ( " GET " , targetURL)
628+ case 307 :
629+ // Re-use existing method:
630+ return ( fromRequest. httpMethod ?? " GET " , targetURL)
631+ default :
632+ return nil
638633 }
639634 }
640-
641635 guard let ( method, targetURL) = methodAndURL ( ) else { return nil }
642636 var request = fromRequest
643637 request. httpMethod = method
0 commit comments