Skip to content

Commit 9d0bf15

Browse files
committed
Add test
1 parent 6780951 commit 9d0bf15

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Tests/Foundation/HTTPServer.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,11 @@ public class TestURLSessionServer {
841841
"Content-Encoding: gzip"].joined(separator: _HTTPUtils.CRLF),
842842
bodyData: helloWorld)
843843
}
844+
845+
if uri == "/echo-query" {
846+
let body = request.parameters.map { "\($0.key)=\($0.value)" }.joined(separator: "&")
847+
return try _HTTPResponse(response: .OK, body: body)
848+
}
844849

845850
// Look for /xxx where xxx is a 3digit HTTP code
846851
if uri.hasPrefix("/") && uri.count == 4, let code = Int(String(uri.dropFirst())), code > 0 && code < 1000 {

Tests/Foundation/Tests/TestURLSession.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,21 @@ class TestURLSession: LoopbackServerTest {
748748
d.run(with: url)
749749
waitForExpectations(timeout: 12)
750750
}
751+
752+
func test_httpRedirectionWithEncodedQuery() {
753+
let location = "echo-query%3Fparam%3Dfoo" // "echo-query?param=foo" url encoded
754+
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/303?location=\(location)"
755+
let url = URL(string: urlString)!
756+
let d = HTTPRedirectionDataTask(with: expectation(description: "GET \(urlString): with HTTP redirection"))
757+
d.run(with: url)
758+
waitForExpectations(timeout: 12)
759+
760+
if let body = String(data: d.receivedData, encoding: .utf8) {
761+
XCTAssertEqual(body, "param=foo")
762+
} else {
763+
XCTFail("No string body")
764+
}
765+
}
751766

752767
// temporarily disabled (https://bugs.swift.org/browse/SR-5751)
753768
func test_httpRedirectionTimeout() {
@@ -1774,6 +1789,7 @@ class TestURLSession: LoopbackServerTest {
17741789
("test_httpRedirectionWithCompleteRelativePath", test_httpRedirectionWithCompleteRelativePath),
17751790
("test_httpRedirectionWithInCompleteRelativePath", test_httpRedirectionWithInCompleteRelativePath),
17761791
("test_httpRedirectionWithDefaultPort", test_httpRedirectionWithDefaultPort),
1792+
("test_httpRedirectionWithEncodedQuery", test_httpRedirectionWithEncodedQuery),
17771793
("test_httpRedirectionTimeout", test_httpRedirectionTimeout),
17781794
("test_httpRedirectionChainInheritsTimeoutInterval", test_httpRedirectionChainInheritsTimeoutInterval),
17791795
("test_httpRedirectionExceededMaxRedirects", test_httpRedirectionExceededMaxRedirects),

0 commit comments

Comments
 (0)