@@ -29,6 +29,7 @@ class TestURLSession : LoopbackServerTest {
2929 ( " test_timeoutInterval " , test_timeoutInterval) ,
3030 ( " test_httpRedirectionWithCompleteRelativePath " , test_httpRedirectionWithCompleteRelativePath) ,
3131 ( " test_httpRedirectionWithInCompleteRelativePath " , test_httpRedirectionWithInCompleteRelativePath) ,
32+ ( " test_httpRedirectionWithDefaultPort " , test_httpRedirectionWithDefaultPort) ,
3233 ( " test_httpRedirectionTimeout " , test_httpRedirectionTimeout) ,
3334 ( " test_http0_9SimpleResponses " , test_http0_9SimpleResponses) ,
3435 ( " test_outOfRangeButCorrectlyFormattedHTTPCode " , test_outOfRangeButCorrectlyFormattedHTTPCode) ,
@@ -345,6 +346,14 @@ class TestURLSession : LoopbackServerTest {
345346 waitForExpectations ( timeout: 12 )
346347 }
347348
349+ func test_httpRedirectionWithDefaultPort( ) {
350+ let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /redirect-with-default-port "
351+ let url = URL ( string: urlString) !
352+ let d = HTTPRedirectionDataTask ( with: expectation ( description: " GET \( urlString) : with HTTP redirection " ) )
353+ d. run ( with: url)
354+ waitForExpectations ( timeout: 12 )
355+ }
356+
348357 // temporarily disabled (https://bugs.swift.org/browse/SR-5751)
349358 func test_httpRedirectionTimeout( ) {
350359 let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /UnitedStates "
@@ -915,6 +924,11 @@ extension HTTPRedirectionDataTask : URLSessionTaskDelegate {
915924 public func urlSession( _ session: URLSession , task: URLSessionTask , willPerformHTTPRedirection response: HTTPURLResponse , newRequest request: URLRequest , completionHandler: @escaping ( URLRequest ? ) -> Void ) {
916925 XCTAssertNotNil ( response)
917926 XCTAssertEqual ( 302 , response. statusCode, " HTTP response code is not 302 " )
927+ if let url = response. url, url. path. hasSuffix ( " /redirect-with-default-port " ) {
928+ XCTAssertEqual ( request. url? . absoluteString, " http://127.0.0.1/redirected-with-default-port " )
929+ // Dont follow the redirect as the test server is not running on port 80
930+ return
931+ }
918932 completionHandler ( request)
919933 }
920934}
0 commit comments