Skip to content

Commit 14c95bf

Browse files
authored
Disable logging by default and add timeout API (#549)
1 parent ce3958f commit 14c95bf

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,41 @@ extension HTTPClient {
3030
func execute(
3131
_ request: HTTPClientRequest,
3232
deadline: NIODeadline,
33-
logger: Logger
33+
logger: Logger? = nil
3434
) async throws -> HTTPClientResponse {
3535
try await self.executeAndFollowRedirectsIfNeeded(
3636
request,
3737
deadline: deadline,
38-
logger: logger,
38+
logger: logger ?? Self.loggingDisabled,
3939
redirectState: RedirectState(self.configuration.redirectConfiguration.mode, initialURL: request.url)
4040
)
4141
}
4242
}
4343

44+
// MARK: Connivence methods
45+
46+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
47+
extension HTTPClient {
48+
/// Execute arbitrary HTTP requests.
49+
///
50+
/// - Parameters:
51+
/// - request: HTTP request to execute.
52+
/// - timeout: time the the request has to complete.
53+
/// - logger: The logger to use for this request.
54+
/// - Returns: The response to the request. Note that the `body` of the response may not yet have been fully received.
55+
func execute(
56+
_ request: HTTPClientRequest,
57+
timeout: TimeAmount,
58+
logger: Logger? = nil
59+
) async throws -> HTTPClientResponse {
60+
try await self.execute(
61+
request,
62+
deadline: .now() + timeout,
63+
logger: logger
64+
)
65+
}
66+
}
67+
4468
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
4569
extension HTTPClient {
4670
private func executeAndFollowRedirectsIfNeeded(

0 commit comments

Comments
 (0)