Skip to content

Commit ab31ed1

Browse files
committed
When redirecting with a relative Location, add the port number to the new URL
1 parent cc28c74 commit ab31ed1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Foundation/URLSession/http/HTTPURLProtocol.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,20 @@ internal extension _HTTPURLProtocol {
391391

392392
// If targetURL has only relative path of url, create a new valid url with relative path
393393
// Otherwise, return request with targetURL ie.url from location field
394-
guard targetURL.scheme == nil || targetURL.host == nil else {
394+
guard targetURL.scheme == nil || targetURL.host == nil || targetURL.port == nil else {
395395
request.url = targetURL
396396
return request
397397
}
398398

399399
let scheme = request.url?.scheme
400400
let host = request.url?.host
401+
let port = request.url?.port
401402

402403
var components = URLComponents()
403404
components.scheme = scheme
404405
components.host = host
406+
components.port = port
407+
405408
//The path must either begin with "/" or be an empty string.
406409
if targetURL.relativeString.first != "/" {
407410
components.path = "/" + targetURL.relativeString

0 commit comments

Comments
 (0)