Skip to content

Commit 7211025

Browse files
authored
add version to response (#182)
* add version to response * fix API breakage by deprecating old init * review fix: use renamed instead of message
1 parent 38bef7c commit 7211025

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Sources/AsyncHTTPClient/HTTPHandler.swift

+22-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ extension HTTPClient {
225225
public var host: String
226226
/// Response HTTP status.
227227
public var status: HTTPResponseStatus
228+
/// Response HTTP version.
229+
public var version: HTTPVersion
228230
/// Reponse HTTP headers.
229231
public var headers: HTTPHeaders
230232
/// Response body.
@@ -237,9 +239,27 @@ extension HTTPClient {
237239
/// - status: Response HTTP status.
238240
/// - headers: Reponse HTTP headers.
239241
/// - body: Response body.
242+
@available(*, deprecated, renamed: "init(host:status:version:headers:body:)")
240243
public init(host: String, status: HTTPResponseStatus, headers: HTTPHeaders, body: ByteBuffer?) {
241244
self.host = host
242245
self.status = status
246+
self.version = HTTPVersion(major: 1, minor: 1)
247+
self.headers = headers
248+
self.body = body
249+
}
250+
251+
/// Create HTTP `Response`.
252+
///
253+
/// - parameters:
254+
/// - host: Remote host of the request.
255+
/// - status: Response HTTP status.
256+
/// - version: Response HTTP version.
257+
/// - headers: Reponse HTTP headers.
258+
/// - body: Response body.
259+
public init(host: String, status: HTTPResponseStatus, version: HTTPVersion, headers: HTTPHeaders, body: ByteBuffer?) {
260+
self.host = host
261+
self.status = status
262+
self.version = version
243263
self.headers = headers
244264
self.body = body
245265
}
@@ -342,9 +362,9 @@ public class ResponseAccumulator: HTTPClientResponseDelegate {
342362
case .idle:
343363
preconditionFailure("no head received before end")
344364
case .head(let head):
345-
return Response(host: self.request.host, status: head.status, headers: head.headers, body: nil)
365+
return Response(host: self.request.host, status: head.status, version: head.version, headers: head.headers, body: nil)
346366
case .body(let head, let body):
347-
return Response(host: self.request.host, status: head.status, headers: head.headers, body: body)
367+
return Response(host: self.request.host, status: head.status, version: head.version, headers: head.headers, body: body)
348368
case .end:
349369
preconditionFailure("request already processed")
350370
case .error(let error):

0 commit comments

Comments
 (0)