Skip to content

Commit 747e3b8

Browse files
committed
cleanup api breakage for response initializers
1 parent b35e140 commit 747e3b8

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ public struct HTTPClientResponse: Sendable {
4646
return URL(string: lastRequestURL)
4747
}
4848

49+
@inlinable public init(
50+
version: HTTPVersion = .http1_1,
51+
status: HTTPResponseStatus = .ok,
52+
headers: HTTPHeaders = [:],
53+
body: Body = Body()
54+
) {
55+
self.version = version
56+
self.status = status
57+
self.headers = headers
58+
self.body = body
59+
self.history = []
60+
}
61+
4962
@inlinable public init(
5063
version: HTTPVersion = .http1_1,
5164
status: HTTPResponseStatus = .ok,
@@ -66,7 +79,7 @@ public struct HTTPClientResponse: Sendable {
6679
status: HTTPResponseStatus,
6780
headers: HTTPHeaders,
6881
body: TransactionBody,
69-
history: [HTTPClientRequestResponse] = []
82+
history: [HTTPClientRequestResponse]
7083
) {
7184
self.init(
7285
version: version,

Sources/AsyncHTTPClient/AsyncAwait/Transaction.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ extension Transaction: HTTPExecutableRequest {
242242
version: head.version,
243243
status: head.status,
244244
headers: head.headers,
245-
body: body
245+
body: body,
246+
history: []
246247
)
247248
continuation.resume(returning: response)
248249
}

Sources/AsyncHTTPClient/HTTPHandler.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,29 @@ extension HTTPClient {
405405
self.history = []
406406
}
407407

408+
/// Create HTTP `Response`.
409+
///
410+
/// - parameters:
411+
/// - host: Remote host of the request.
412+
/// - status: Response HTTP status.
413+
/// - version: Response HTTP version.
414+
/// - headers: Reponse HTTP headers.
415+
/// - body: Response body.
416+
public init(
417+
host: String,
418+
status: HTTPResponseStatus,
419+
version: HTTPVersion,
420+
headers: HTTPHeaders,
421+
body: ByteBuffer?
422+
) {
423+
self.host = host
424+
self.status = status
425+
self.version = version
426+
self.headers = headers
427+
self.body = body
428+
self.history = []
429+
}
430+
408431
/// Create HTTP `Response`.
409432
///
410433
/// - parameters:

0 commit comments

Comments
 (0)