Skip to content

Commit af5966f

Browse files
authored
Reduce use of HTTPClient.Configuration in the Connection objects (#635)
1 parent 64ff430 commit af5966f

File tree

6 files changed

+28
-57
lines changed

6 files changed

+28
-57
lines changed

‎Sources/AsyncHTTPClient/ConnectionPool/HTTP1/HTTP1Connection.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ final class HTTP1Connection{
5757
channel:Channel,
5858
connectionID:HTTPConnectionPool.Connection.ID,
5959
delegate:HTTP1ConnectionDelegate,
60-
configuration:HTTPClient.Configuration,
60+
decompression:HTTPClient.Decompression,
6161
logger:Logger
6262
)throws->HTTP1Connection{
6363
letconnection=HTTP1Connection(channel: channel, connectionID: connectionID, delegate: delegate)
64-
try connection.start(configuration: configuration, logger: logger)
64+
try connection.start(decompression: decompression, logger: logger)
6565
return connection
6666
}
6767

@@ -101,7 +101,7 @@ final class HTTP1Connection{
101101
self.channel.write(request, promise:nil)
102102
}
103103

104-
privatefunc start(configuration:HTTPClient.Configuration, logger:Logger)throws{
104+
privatefunc start(decompression:HTTPClient.Decompression, logger:Logger)throws{
105105
self.channel.eventLoop.assertInEventLoop()
106106

107107
guard case .initialized =self.state else{
@@ -127,7 +127,7 @@ final class HTTP1Connection{
127127
try sync.addHandler(requestEncoder)
128128
try sync.addHandler(ByteToMessageHandler(responseDecoder))
129129

130-
if case .enabled(let limit)=configuration.decompression {
130+
if case .enabled(let limit)= decompression {
131131
letdecompressHandler=NIOHTTPResponseDecompressor(limit: limit)
132132
try sync.addHandler(decompressHandler)
133133
}

‎Sources/AsyncHTTPClient/ConnectionPool/HTTP2/HTTP2Connection.swift‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@ final class HTTP2Connection{
119119
channel:Channel,
120120
connectionID:HTTPConnectionPool.Connection.ID,
121121
delegate:HTTP2ConnectionDelegate,
122-
configuration:HTTPClient.Configuration,
122+
decompression:HTTPClient.Decompression,
123123
logger:Logger
124124
)->EventLoopFuture<(HTTP2Connection,Int)>{
125-
letconnection=HTTP2Connection(channel: channel, connectionID: connectionID, decompression: configuration.decompression, delegate: delegate, logger: logger)
125+
letconnection=HTTP2Connection(
126+
channel: channel,
127+
connectionID: connectionID,
128+
decompression: decompression,
129+
delegate: delegate,
130+
logger: logger
131+
)
126132
return connection.start().map{ maxStreams in(connection, maxStreams)}
127133
}
128134

‎Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift‎

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extension HTTPConnectionPool.ConnectionFactory{
7171
channel: channel,
7272
connectionID: connectionID,
7373
delegate: http1ConnectionDelegate,
74-
configuration:self.clientConfiguration,
74+
decompression:self.clientConfiguration.decompression,
7575
logger: logger
7676
)
7777
requester.http1ConnectionCreated(connection)
@@ -83,7 +83,7 @@ extension HTTPConnectionPool.ConnectionFactory{
8383
channel: channel,
8484
connectionID: connectionID,
8585
delegate: http2ConnectionDelegate,
86-
configuration:self.clientConfiguration,
86+
decompression:self.clientConfiguration.decompression,
8787
logger: logger
8888
).whenComplete{ result in
8989
switch result {
@@ -105,41 +105,6 @@ extension HTTPConnectionPool.ConnectionFactory{
105105
case http2(Channel)
106106
}
107107

108-
func makeHTTP1Channel<Requester:HTTPConnectionRequester>(
109-
requester:Requester,
110-
connectionID:HTTPConnectionPool.Connection.ID,
111-
deadline:NIODeadline,
112-
eventLoop:EventLoop,
113-
logger:Logger
114-
)->EventLoopFuture<Channel>{
115-
self.makeChannel(
116-
requester: requester,
117-
connectionID: connectionID,
118-
deadline: deadline,
119-
eventLoop: eventLoop,
120-
logger: logger
121-
).flatMapThrowing{ negotiated ->Channelin
122-
123-
guard case .http1_1(let channel)= negotiated else{
124-
preconditionFailure("Expected to create http/1.1 connections only for now")
125-
}
126-
127-
// add the http1.1 channel handlers
128-
letsyncOperations= channel.pipeline.syncOperations
129-
try syncOperations.addHTTPClientHandlers(leftOverBytesStrategy:.forwardBytes)
130-
131-
switchself.clientConfiguration.decompression {
132-
case.disabled:
133-
()
134-
case.enabled(let limit):
135-
letdecompressHandler=NIOHTTPResponseDecompressor(limit: limit)
136-
try syncOperations.addHandler(decompressHandler)
137-
}
138-
139-
return channel
140-
}
141-
}
142-
143108
func makeChannel<Requester:HTTPConnectionRequester>(
144109
requester:Requester,
145110
connectionID:HTTPConnectionPool.Connection.ID,

‎Tests/AsyncHTTPClientTests/EmbeddedChannel+HTTPConvenience.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extension EmbeddedChannel{
7777
channel:self,
7878
connectionID:1,
7979
delegate: connectionDelegate,
80-
configuration:.init(),
80+
decompression:.disabled,
8181
logger: logger
8282
)
8383

‎Tests/AsyncHTTPClientTests/HTTP1ConnectionTests.swift‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class HTTP1ConnectionTests: XCTestCase{
3535
channel: embedded,
3636
connectionID:0,
3737
delegate:MockHTTP1ConnectionDelegate(),
38-
configuration:.init(decompression:.enabled(limit:.ratio(4))),
38+
decompression:.enabled(limit:.ratio(4)),
3939
logger: logger
4040
))
4141

@@ -58,7 +58,7 @@ class HTTP1ConnectionTests: XCTestCase{
5858
channel: embedded,
5959
connectionID:0,
6060
delegate:MockHTTP1ConnectionDelegate(),
61-
configuration:.init(decompression:.disabled),
61+
decompression:.disabled,
6262
logger: logger
6363
))
6464

@@ -82,7 +82,7 @@ class HTTP1ConnectionTests: XCTestCase{
8282
channel: embedded,
8383
connectionID:0,
8484
delegate:MockHTTP1ConnectionDelegate(),
85-
configuration:.init(),
85+
decompression:.disabled,
8686
logger: logger
8787
))
8888
}
@@ -106,7 +106,7 @@ class HTTP1ConnectionTests: XCTestCase{
106106
channel: $0,
107107
connectionID:0,
108108
delegate: delegate,
109-
configuration:.init(decompression:.disabled),
109+
decompression:.disabled,
110110
logger: logger
111111
)
112112
}
@@ -206,7 +206,7 @@ class HTTP1ConnectionTests: XCTestCase{
206206
channel:XCTUnwrap(maybeChannel),
207207
connectionID:0,
208208
delegate: connectionDelegate,
209-
configuration:.init(),
209+
decompression:.disabled,
210210
logger: logger
211211
)}.wait())
212212
guardlet connection = maybeConnection else{returnXCTFail("Expected to have a connection here")}
@@ -260,7 +260,7 @@ class HTTP1ConnectionTests: XCTestCase{
260260
channel:XCTUnwrap(maybeChannel),
261261
connectionID:0,
262262
delegate: connectionDelegate,
263-
configuration:.init(),
263+
decompression:.disabled,
264264
logger: logger
265265
)}.wait())
266266
guardlet connection = maybeConnection else{returnXCTFail("Expected to have a connection here")}
@@ -332,7 +332,7 @@ class HTTP1ConnectionTests: XCTestCase{
332332
channel:XCTUnwrap(maybeChannel),
333333
connectionID:0,
334334
delegate: connectionDelegate,
335-
configuration:.init(),
335+
decompression:.disabled,
336336
logger: logger
337337
)}.wait())
338338
guardlet connection = maybeConnection else{returnXCTFail("Expected to have a connection here")}
@@ -377,7 +377,7 @@ class HTTP1ConnectionTests: XCTestCase{
377377
channel: embedded,
378378
connectionID:0,
379379
delegate: connectionDelegate,
380-
configuration:.init(decompression:.enabled(limit:.ratio(4))),
380+
decompression:.enabled(limit:.ratio(4)),
381381
logger: logger
382382
))
383383
guardlet connection = maybeConnection else{returnXCTFail("Expected to have a connection at this point.")}
@@ -442,7 +442,7 @@ class HTTP1ConnectionTests: XCTestCase{
442442
channel: embedded,
443443
connectionID:0,
444444
delegate: connectionDelegate,
445-
configuration:.init(decompression:.enabled(limit:.ratio(4))),
445+
decompression:.enabled(limit:.ratio(4)),
446446
logger: logger
447447
))
448448
guardlet connection = maybeConnection else{returnXCTFail("Expected to have a connection at this point.")}
@@ -504,7 +504,7 @@ class HTTP1ConnectionTests: XCTestCase{
504504
channel: embedded,
505505
connectionID:0,
506506
delegate: connectionDelegate,
507-
configuration:.init(decompression:.enabled(limit:.ratio(4))),
507+
decompression:.enabled(limit:.ratio(4)),
508508
logger: logger
509509
))
510510

@@ -539,7 +539,7 @@ class HTTP1ConnectionTests: XCTestCase{
539539
channel: embedded,
540540
connectionID:0,
541541
delegate: connectionDelegate,
542-
configuration:.init(decompression:.enabled(limit:.ratio(4))),
542+
decompression:.enabled(limit:.ratio(4)),
543543
logger: logger
544544
))
545545
guardlet connection = maybeConnection else{returnXCTFail("Expected to have a connection at this point.")}
@@ -691,7 +691,7 @@ class HTTP1ConnectionTests: XCTestCase{
691691
channel: channel,
692692
connectionID:0,
693693
delegate: connectionDelegate,
694-
configuration:.init(),
694+
decompression:.disabled,
695695
logger: logger
696696
)}.wait())
697697
guardlet connection = maybeConnection else{returnXCTFail("Expected to have a connection at this point")}

‎Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class HTTP2ConnectionTests: XCTestCase{
3737
channel: embedded,
3838
connectionID:0,
3939
delegate:TestHTTP2ConnectionDelegate(),
40-
configuration:.init(),
40+
decompression:.disabled,
4141
logger: logger
4242
).wait())
4343
}

0 commit comments

Comments
(0)