-
Notifications
You must be signed in to change notification settings - Fork 125
Refactor deconstructURL
and scheme
parsing
#504
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
Conversation
Conflicts: Sources/AsyncHTTPClient/ConnectionPool.swift Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift Sources/AsyncHTTPClient/HTTPHandler.swift Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift
@swift-server-bot test this please |
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.
All in all looks good. Few changes wanted.
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation |
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.
NIT: Only import what is actually needed.
import Foundation | |
import struct Foundation.URL |
} | ||
|
||
extension DeconstructedURL.Scheme { | ||
var useTLS: Bool { |
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.
He, she, it das s muss mit ;)
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.
We will diverge from the public API on HTTPClient.Request but I’m okay with that
enum Scheme: String { | ||
case http | ||
case https | ||
case unix | ||
case httpUnix = "http+unix" | ||
case httpsUnix = "https+unix" | ||
} |
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'm not sure this should be namespaced in DeconstructedURL. Would you mind moving this out?
- rename `useTLS` to `usesTLS` where posible without breaking public API - only import Foundation.URL
@@ -748,7 +748,7 @@ internal struct RedirectHandler<ResponseType> { | |||
} | |||
} | |||
|
|||
extension DeconstructedURL.Scheme { | |||
extension Scheme { |
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 think this should live in the Scheme file.
/// Parsed, validated and deconstructed URL. | ||
internal let deconstructedURL: DeconstructedURL | ||
|
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.
NIT: Move down to other internal var like redirect state. Mixing internal and public makes this hard to read.
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.
Very cool, except for the tiny nits.
@swift-server-bot test this please |
One thing that might be worth considering is if the scheme can just be dropped?
Because it now knows which kind of connection target it has, the only thing the scheme provides is whether to use TLS. |
Sadly we expose the scheme as public API. Not as the |
Technically, it could get that from the URL. There's no need for ConnectionPool or most other things to know specifically which kind of scheme was used (also, |
I disagree with this: the scheme is meaningfully part of both the origin and the network key for a request, and so should use different connections. |
The problem here are http semantics. From an http standpoint |
I'm not sure to what extent HTTP really intends to define the semantics of non- |
HTTP does not define them. I agree that in principle we can define them however we want. Given that schemes are explicitly part of the connection pooling pattern in fetch, the most prudent choice is to generalise that idea to these schemes, especially as there are very few practical problems caused by doing so. |
Motivation
We want to reuse our URL parsing, validation and deconstruction logic for the upcoming new
HTTPClientRequest
from the async/await proposal.Changes
DeconstructedURL
struct which hold ascheme
,connectionTarget
anduri
.DeconstructedURL.Scheme
enum which replaced the previousString
inHTTPClient.Request
andConnectionPool.Scheme
enumdeconstructURL
logic to an initialiser ofDeconstructedURL
DeconstructedURL
instead of separatescheme
,connectionTarget
, anduri
properties inHTTPClient.Request
HTTPClient.Request.Kind
because it is almost a replica of theDeconstructedURL.Scheme
enum where the only difference is thathttp
andhttps
are represented as one case calledhost
. As we now representscheme
as an enum instead of aString
we can safely replace it with an exhaustive switch overscheme
instead.scheme
instead ofkind
config(overriding:)
fromConnectionPool.Key