Open
Description
Request for Change
The swift-http-types
package was added by @zunda-pixel in the #564 which refactored the internal HTTPHeaders
type to use the HTTPFields
from the package.
The swift-http-types
also provides both HTTPRequest
and HTTPResponse
generic types.
Current behavior
We currently have both HTTPRequest
and HTTPResponse
types that we use internally for all requests/responses.
New behavior
Refactor internal HTTP layer to use types from swift-http-types
package.
Open questions
swift-http-types
doesn't standardize the body property, that is up to us to define how we're handling it.
I suggest the refactor of the HTTPClientType
to be:
func send(for request: HTTPRequest, body: Data?) async throws -> (Data, HTTPResponse)
And forward to upload(from:body:)
in case a non-nil body is provided, or data(for:)
, as:
func send(for request: HTTPRequest, body: Data?) async throws -> (Data, HTTPResponse) {
let (data, response) = if let body {
try await session.upload(for: request, body: body)
} else {
try await session.data(for: request)
}
let httpResponse = HTTPResponse(response as! HTTPURLResponse)
return (data, httpResponse)
}