Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/NIOHTTPClient/HTTPHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ extension HTTPClientResponseDelegate {

internal extension URL {
var uri: String {
return path.isEmpty ? "/" : path + (query.map { "?" + $0 } ?? "")
let urlEncodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? path
return path.isEmpty ? "/" : urlEncodedPath + (query.map { "?" + $0 } ?? "")
}

func hasTheSameOrigin(as other: URL) -> Bool {
Expand Down
8 changes: 8 additions & 0 deletions Tests/NIOHTTPClientTests/HTTPClientTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ internal final class HttpBinHandler: ChannelInboundHandler {
headers.add(name: "Location", value: "http://127.0.0.1:\(port)/echohostheader")
self.resps.append(HTTPResponseBuilder(status: .found, headers: headers))
return
// Since this String is taken from URL.path, the percent encoding has been removed
case "/percent encoded":
if req.method != .GET {
self.resps.append(HTTPResponseBuilder(status: .methodNotAllowed))
return
}
self.resps.append(HTTPResponseBuilder(status: .ok))
return
case "/echohostheader":
var builder = HTTPResponseBuilder(status: .ok)
let hostValue = req.headers["Host"].first ?? ""
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTPClientTests/HTTPClientTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extension HTTPClientTests {
("testPostHttps", testPostHttps),
("testHttpRedirect", testHttpRedirect),
("testHttpHostRedirect", testHttpHostRedirect),
("testPercentEncoded", testPercentEncoded),
("testMultipleContentLengthHeaders", testMultipleContentLengthHeaders),
("testStreaming", testStreaming),
("testRemoteClose", testRemoteClose),
Expand Down
12 changes: 12 additions & 0 deletions Tests/NIOHTTPClientTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ class HTTPClientTests: XCTestCase {
let hostName = try decoder.decode([String: String].self, from: responseData)["data"]
XCTAssert(hostName == "127.0.0.1")
}

func testPercentEncoded() throws {
let httpBin = HttpBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer {
try! httpClient.syncShutdown()
httpBin.shutdown()
}

let response = try httpClient.get(url: "http://localhost:\(httpBin.port)/percent%20encoded").wait()
XCTAssertEqual(.ok, response.status)
}

func testMultipleContentLengthHeaders() throws {
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
Expand Down