Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add %-encoding in ClientRequest.init, remove in HTTPServerRequest.init #171

Merged
merged 1 commit into from
Mar 14, 2019
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
2 changes: 1 addition & 1 deletion Sources/KituraNet/ClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public class ClientRequest {
if thePath.first != "/" {
thePath = "/" + thePath
}
path = thePath
path = thePath.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) ?? thePath
self.path = path
case .username(let userName):
self.userName = userName
Expand Down
15 changes: 13 additions & 2 deletions Sources/KituraNet/HTTP/HTTPServerRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,18 @@ public class HTTPServerRequest: ServerRequest {

private var enableSSL: Bool = false

private var _urlString: String
private var rawURLString: String

private var urlStringPercentEncodingRemoved: String?

private var _urlString: String {
guard let urlStringPercentEncodingRemoved = self.urlStringPercentEncodingRemoved else {
let _urlStringPercentEncodingRemoved = rawURLString.removingPercentEncoding ?? rawURLString
self.urlStringPercentEncodingRemoved = _urlStringPercentEncodingRemoved
return _urlStringPercentEncodingRemoved
}
return urlStringPercentEncodingRemoved
}

private static func host(socketAddress: SocketAddress?) -> String {
guard let socketAddress = socketAddress else {
Expand All @@ -148,7 +159,7 @@ public class HTTPServerRequest: ServerRequest {
self.method = requestHead.method.string()
self.httpVersionMajor = requestHead.version.major
self.httpVersionMinor = requestHead.version.minor
self._urlString = requestHead.uri
self.rawURLString = requestHead.uri
self.enableSSL = enableSSL
}

Expand Down
14 changes: 14 additions & 0 deletions Tests/KituraNetTests/ClientRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ class ClientRequestTests: KituraNetTest {
let options = ClientRequest.parse("https://username:password@66o.tech:8080/path?key=value")
let testRequest = ClientRequest(options: options, callback: testCallback)
XCTAssertEqual(testRequest.url, "https://username:password@66o.tech:8080/path?key=value")

let options1: [ClientRequest.Options] = [ .schema("https"),
.hostname("66o.tech"),
.path("/view/matching?key=\"viewTest\"")
]
let testRequest1 = ClientRequest(options: options1, callback: testCallback)
XCTAssertEqual(testRequest1.url, "https://66o.tech/view/matching?key=%22viewTest%22")

let options2: [ClientRequest.Options] = [ .schema("https"),
.hostname("66o.tech"),
.path("/view/match?key?=value?")
]
let testRequest2 = ClientRequest(options: options2, callback: testCallback)
XCTAssertEqual(testRequest2.url, "https://66o.tech/view/match?key?=value?")
}

func testClientRequestBasicAuthentcation() {
Expand Down