@@ -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) ,
@@ -345,6 +346,14 @@ class TestURLSession : LoopbackServerTest {
345
346
waitForExpectations ( timeout: 12 )
346
347
}
347
348
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
+
348
357
// temporarily disabled (https://bugs.swift.org/browse/SR-5751)
349
358
func test_httpRedirectionTimeout( ) {
350
359
let urlString = " http://127.0.0.1: \( TestURLSession . serverPort) /UnitedStates "
@@ -915,6 +924,11 @@ extension HTTPRedirectionDataTask : URLSessionTaskDelegate {
915
924
public func urlSession( _ session: URLSession , task: URLSessionTask , willPerformHTTPRedirection response: HTTPURLResponse , newRequest request: URLRequest , completionHandler: @escaping ( URLRequest ? ) -> Void ) {
916
925
XCTAssertNotNil ( response)
917
926
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
+ }
918
932
completionHandler ( request)
919
933
}
920
934
}
0 commit comments