Create the default RequestOptions from the client instead of using a required init#97
Create the default RequestOptions from the client instead of using a required init#97guoye-zhang wants to merge 4 commits intoapple:mainfrom
Conversation
| public var allowsExpensiveNetworkAccess: Bool = true | ||
| public var allowsConstrainedNetworkAccess: Bool = true | ||
|
|
||
| public init() {} |
There was a problem hiding this comment.
Should I remove the initializer on the concrete client's options or keep it? It might be confusing whether there is a difference between HTTPRequestOptions() and DefaultHTTPClient.shared.defaultRequestOptions, but it's way less discoverable.
There was a problem hiding this comment.
Depends on whether you anticipate ever needing to inspect the client's state before constructing a new options value. If not, you could either keep the init, or use something a bit more self-documenting, like:
public static var `default`: Self { .init() }| request: HTTPRequest, | ||
| body: consuming HTTPClientRequestBody<RequestWriter>?, | ||
| options: RequestOptions, | ||
| options: RequestOptions?, |
There was a problem hiding this comment.
Filed this to continue the nil vs non-nil discussion: #98
|
|
||
| /// The default request options for `perform`. | ||
| var defaultRequestOptions: RequestOptions { get } |
There was a problem hiding this comment.
NIT: can we move this above the perform method since we normally do properties first then methods.
|
I added the empty initializer back. We now have 3 ways to express the same thing:
I would like to discuss if it's actually a good idea for |
I think we need to think about the developer experience when making the decision here: // This only works with 2.
func foo(client: some HTTPClient) async throws {
var options = client.defaultRequestOptions
options.someSetting = true
}
// .init forces this
func foo<Client: HTTPClient>(client: Client) async throws {
var options = Client.RequestOptions()
options.someSetting = true
}Just for that reason I think we should go with 2.. Now the other question is if we should make the requestOptions parameter on the protocol requirement optional or non-optional. If it is optional we need to define what clients should do. I personally believe it is best to make it non-optional on the protocol and the conveniences can make it optional and state that they call |
Related discussion in #71