@@ -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) ,
@@ -337,6 +338,14 @@ class TestURLSession : LoopbackServerTest {
337338 waitForExpectations ( timeout: 12 )
338339 }
339340
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+
340349 // temporarily disabled (https://bugs.swift.org/browse/SR-5751)
341350 func test_httpRedirectionTimeout( ) {
342351 let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /UnitedStates "
@@ -893,6 +902,11 @@ extension HTTPRedirectionDataTask : URLSessionTaskDelegate {
893902 public func urlSession( _ session: URLSession , task: URLSessionTask , willPerformHTTPRedirection response: HTTPURLResponse , newRequest request: URLRequest , completionHandler: @escaping ( URLRequest ? ) -> Void ) {
894903 XCTAssertNotNil ( response)
895904 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+ }
896910 completionHandler ( request)
897911 }
898912}
0 commit comments