-
Notifications
You must be signed in to change notification settings - Fork 51
improve API usages around String/Data/ByteBuffer #109
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
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.
These all look good
@weissi Actually the HTTPClient code will need backed out. We need to provide support for a http client with proxy settings so cannot use the shared client. |
Shouldn't Alternatively, once proxy support is ready you could create your own singleton in Swiftly. |
That'd be nice. I don't think it does at the moment. |
@@ -186,9 +185,5 @@ public struct SwiftlyHTTPClient { | |||
} | |||
|
|||
private class HTTPClientWrapper { |
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.
If we go the shared route, I don't think we need this class at all actually. The original intent was to be able to share a single HTTP client via class
's arc semantics and also to ensure it shut down when the application was shutting down, both of which seem to be solved by HTTPClient.shared
.
If we don't go this route, then we probably still can get rid of this assuming we don't need to call syncShutdown
ourselves, which it seems like we don't need to?
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.
If we go the shared route, I don't think we need this class at all actually. The original intent was to be able to share a single HTTP client via class's arc semantics and also to ensure it shut down when the application was shutting down, both of which seem to be solved by HTTPClient.shared.
Right, this doesn't really work because you can't know what thread will call deinit
, so if you call syncShutdown
in there that can be pretty bad.
There are really two 'correct' ways:
- in
main
call:let client = HTTPClient(...); defer { try! client.syncShutdown() }
and dependency inject it - use a singleton. Either
HTTPClient.shared
or your own singleton
Most server people prefer (1) but Apple's SDKs are typically singleton-heavy and therefore the Swift community is often quite keen on simplicity which would be (2). Especially for a command-line utility like Swiftly, having a HTTPClient-singleton isn't really that bad.
Of course it's a serious design issue in HTTPClient that some of the configuration (like the proxy settings) can only be configured using the top-level object (HTTPClient
) that you're really meant to share everywhere (swift-server/async-http-client#392).
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.
Yeah, I think a singleton would be fine for swiftly, it's basically what we have already. Until shared
can be configured to handle the proxy settings, it seems like we'll need to do it ourselves though. I think we can do that in a separate commit / PR or here if you'd like, either is fine with me.
No, but it should and it shouldn't be hard to implement I think. |
I'm good with this going in just now. We can resolve the proxy thing separately |
Thanks. Why don't we do that so we can move forward. |
sgtm |
thanks for the contribution! |
String(data:encoding)
to the betterString(decoding:as:)
String.data(encoding:)
to the betterData(string.utf8)
ByteBuffer
conversiondeinit
abuse