-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
8e4088c
to
4b12bfb
Compare
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
=======================================
Coverage 68.64% 68.64%
=======================================
Files 20 20
Lines 1298 1298
=======================================
Hits 891 891
Misses 407 407
Continue to review full report at Codecov.
|
dabe88d
to
00583e0
Compare
@djones6 Could you please review? There are three caveats here:
|
@pushkarnk How does ClientRequest in Kitura-net handle this? (is it handled for us by curl?) To answer your questions above:
Another question would be: should we instead by transmitting the credentials in an
|
Thank for the review @djones6 ... To answer the two questions you asked:
|
if urlStringPercentEncodingRemoved == nil { | ||
urlStringPercentEncodingRemoved = rawURLString.removingPercentEncoding ?? rawURLString | ||
} | ||
return urlStringPercentEncodingRemoved! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see this code is correct, but could we use guard let here so that we don't need the force-unwrap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djones6 Using guard-let
and not force-unwrapping it can look only as good as this:
private var _urlString: String {
guard let urlStringPercentEncodingRemoved = self.urlStringPercentEncodingRemoved else {
self.urlStringPercentEncodingRemoved = rawURLString.removingPercentEncoding ?? rawURLString
return rawURLString.removingPercentEncoding ?? rawURLString
}
return urlStringPercentEncodingRemoved
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let result = rawURLString.removingPercentEncoding ?? rawURLString
self.urlStringPercentEncodingRemoved = result
return result
It's important not to run removingPercentEncoding
twice as it is quite expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks @djones6 !
00583e0
to
a8ee59f
Compare
This is related to a test failure in CouchDB: Kitura/Kitura-CouchDB#91
During the initialisation of ClientRequest, the
path
component, which, inClientRequest
, includesquery
component, needs to be percent encoded. On the other side, during the initialisation of an HTTPServerRequest, we'd need to remove the percent encoding.ClientRequest.Options.path includes the fragment, path and query components. The only character which is permissible in a fragment and a query but not in a path is
?
. To avoid further parsing here, we could go with percent-encoding a?
in the path string too.A word on encoding
?
This does not pertain to the
?
as in:https://66o.tech/path?q=v
. This pertains to a?
as in:https://66o.tech/pa?th?q=?v
which after %-encoding will becomehttps://66o.tech/pa%3Fth?q=%3Fv
, thoughhttps://66o.tech/pa%3Fth?q=?v
is permissible per the definition of NSCharacterSet.urlQueryAllowed.In the proposed change, the
?
character will not be percent-encoded in the path (fragment, path and query), though it should be encoded in the "path". I'm assuming that paths like "/this?path" are rare in occurrence. Percent encoding '?' will make parsing ClientRequest.path all the more complicated and we may want to avoid it until it is explicitly asked for.The fact that
ClientRequest.Options.path
includes path and query is a design weakness in this context.Other components like
host
anduser
may also be percent-encoded, but are those cases really common?