-
Notifications
You must be signed in to change notification settings - Fork 125
Resolve ambiguity issue of stream
#748
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
… length. Change type for length from `Int64?` to enum-backed type.
if case .known(let count) = self.contentLength.length { | ||
return Int(count) | ||
} | ||
return nil |
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: prefer switching exhaustively over enums
} | ||
} | ||
|
||
/// Body size. If nil,`Transfer-Encoding` will automatically be set to `chunked`. Otherwise a `Content-Length` | ||
/// header is set with the given `contentLength`. | ||
public var contentLength: Int64? | ||
public var contentLength: Length |
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 can't make this change, it's an API break. We could work around it by adding a new length property using the new type and have computed getters/setters on contentLength
.
However I don't think we should make this change: Length
doesn't allow the user to recover the (known) length value. I think if we want to use this type it should only be at the surface level in the stream
func
. It also makes me wonder whether we should do this at all and just use @_disfavoredOverload
. WDYT @FranzBusch?
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.
This is a new not an API break because we haven't released the API yet afaik but I agree exposing this var is weird. @fabianfett what do you think?
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 haven't released this API yet. Therefore this will not be a breaking change. Generally I'm in favor of using @_disfavoredOverload
on the Int
version of this API as well as the initializers that use trailing closure syntax.
Closing this PR as it now has too many unneeded changes and creating a new one with the |
Motivation:
stream
function inHTTPClientRequest.Body
(newly added in Add support for request body to be larger than 2GB on 32-bit devices #746) is ambiguous with the existingstream
function as the first argument has a default value and the second argument is a closure. This is API-breaking.Modifications:
nil
.Int64?
to an enum-backed structLength
. This struct uses the existing internal enumRequestBodyLength
which has cases.unknown
and.known(_ count: Int64)
.Result:
stream
function (as well as the initializer forBody
) is now more readable as it has to be spelled out explicitly as.unknown
rather than an unclearnil
.