@@ -29,6 +29,7 @@ class TestURLSession : LoopbackServerTest {
29
29
( " test_timeoutInterval " , test_timeoutInterval) ,
30
30
( " test_httpRedirectionWithCompleteRelativePath " , test_httpRedirectionWithCompleteRelativePath) ,
31
31
( " test_httpRedirectionWithInCompleteRelativePath " , test_httpRedirectionWithInCompleteRelativePath) ,
32
+ ( " test_httpRedirectionWithDefaultPort " , test_httpRedirectionWithDefaultPort) ,
32
33
( " test_httpRedirectionTimeout " , test_httpRedirectionTimeout) ,
33
34
( " test_http0_9SimpleResponses " , test_http0_9SimpleResponses) ,
34
35
( " test_outOfRangeButCorrectlyFormattedHTTPCode " , test_outOfRangeButCorrectlyFormattedHTTPCode) ,
@@ -337,6 +338,14 @@ class TestURLSession : LoopbackServerTest {
337
338
waitForExpectations ( timeout: 12 )
338
339
}
339
340
341
+ func test_httpRedirectionWithDefaultPort( ) {
342
+ let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /redirect-with-default-port "
343
+ let url = URL ( string: urlString) !
344
+ let d = HTTPRedirectionDataTask ( with: expectation ( description: " GET \( urlString) : with HTTP redirection " ) )
345
+ d. run ( with: url)
346
+ waitForExpectations ( timeout: 12 )
347
+ }
348
+
340
349
// temporarily disabled (https://bugs.swift.org/browse/SR-5751)
341
350
func test_httpRedirectionTimeout( ) {
342
351
let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /UnitedStates "
@@ -893,6 +902,11 @@ extension HTTPRedirectionDataTask : URLSessionTaskDelegate {
893
902
public func urlSession( _ session: URLSession , task: URLSessionTask , willPerformHTTPRedirection response: HTTPURLResponse , newRequest request: URLRequest , completionHandler: @escaping ( URLRequest ? ) -> Void ) {
894
903
XCTAssertNotNil ( response)
895
904
XCTAssertEqual ( 302 , response. statusCode, " HTTP response code is not 302 " )
905
+ if let url = response. url, url. path. hasSuffix ( " /redirect-with-default-port " ) {
906
+ XCTAssertEqual ( request. url? . absoluteString, " http://127.0.0.1/redirected-with-default-port " )
907
+ // Dont follow the redirect as the test server is not running on port 80
908
+ return
909
+ }
896
910
completionHandler ( request)
897
911
}
898
912
}
0 commit comments