Skip to content

Commit c8ca8d7

Browse files
authored
Add basic configuration extension (#962)
1 parent 0169671 commit c8ca8d7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
import AsyncHTTPClient
9+
import NIOCore
10+
11+
extension HTTPClient.Configuration {
12+
13+
static func from(httpClientConfiguration: HttpClientConfiguration) -> HTTPClient.Configuration {
14+
let connect: TimeAmount? = httpClientConfiguration.connectTimeout != nil
15+
? .seconds(Int64(httpClientConfiguration.connectTimeout!))
16+
: nil
17+
18+
let read: TimeAmount? = .seconds(Int64(httpClientConfiguration.socketTimeout))
19+
20+
let timeout = HTTPClient.Configuration.Timeout(
21+
connect: connect,
22+
read: read
23+
)
24+
25+
let pool = HTTPClient.Configuration.ConnectionPool(
26+
idleTimeout: .seconds(60), // default
27+
concurrentHTTP1ConnectionsPerHostSoftLimit: httpClientConfiguration.maxConnections
28+
)
29+
30+
return .init(
31+
tlsConfiguration: nil, // TODO
32+
redirectConfiguration: nil,
33+
timeout: timeout,
34+
connectionPool: pool,
35+
proxy: nil,
36+
ignoreUncleanSSLShutdown: false,
37+
decompression: .disabled
38+
)
39+
}
40+
}

0 commit comments

Comments
 (0)