Skip to content

Reduce use of HTTPClient.Configuration in the Connection objects #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ final class HTTP1Connection {
channel: Channel,
connectionID: HTTPConnectionPool.Connection.ID,
delegate: HTTP1ConnectionDelegate,
configuration: HTTPClient.Configuration,
decompression: HTTPClient.Decompression,
logger: Logger
) throws -> HTTP1Connection {
let connection = HTTP1Connection(channel: channel, connectionID: connectionID, delegate: delegate)
try connection.start(configuration: configuration, logger: logger)
try connection.start(decompression: decompression, logger: logger)
return connection
}

Expand Down Expand Up @@ -101,7 +101,7 @@ final class HTTP1Connection {
self.channel.write(request, promise: nil)
}

private func start(configuration: HTTPClient.Configuration, logger: Logger) throws {
private func start(decompression: HTTPClient.Decompression, logger: Logger) throws {
self.channel.eventLoop.assertInEventLoop()

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

if case .enabled(let limit) = configuration.decompression {
if case .enabled(let limit) = decompression {
let decompressHandler = NIOHTTPResponseDecompressor(limit: limit)
try sync.addHandler(decompressHandler)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,16 @@ final class HTTP2Connection {
channel: Channel,
connectionID: HTTPConnectionPool.Connection.ID,
delegate: HTTP2ConnectionDelegate,
configuration: HTTPClient.Configuration,
decompression: HTTPClient.Decompression,
logger: Logger
) -> EventLoopFuture<(HTTP2Connection, Int)> {
let connection = HTTP2Connection(channel: channel, connectionID: connectionID, decompression: configuration.decompression, delegate: delegate, logger: logger)
let connection = HTTP2Connection(
channel: channel,
connectionID: connectionID,
decompression: decompression,
delegate: delegate,
logger: logger
)
return connection.start().map { maxStreams in (connection, maxStreams) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension HTTPConnectionPool.ConnectionFactory {
channel: channel,
connectionID: connectionID,
delegate: http1ConnectionDelegate,
configuration: self.clientConfiguration,
decompression: self.clientConfiguration.decompression,
logger: logger
)
requester.http1ConnectionCreated(connection)
Expand All @@ -83,7 +83,7 @@ extension HTTPConnectionPool.ConnectionFactory {
channel: channel,
connectionID: connectionID,
delegate: http2ConnectionDelegate,
configuration: self.clientConfiguration,
decompression: self.clientConfiguration.decompression,
logger: logger
).whenComplete { result in
switch result {
Expand All @@ -105,41 +105,6 @@ extension HTTPConnectionPool.ConnectionFactory {
case http2(Channel)
}

func makeHTTP1Channel<Requester: HTTPConnectionRequester>(
requester: Requester,
connectionID: HTTPConnectionPool.Connection.ID,
deadline: NIODeadline,
eventLoop: EventLoop,
logger: Logger
) -> EventLoopFuture<Channel> {
self.makeChannel(
requester: requester,
connectionID: connectionID,
deadline: deadline,
eventLoop: eventLoop,
logger: logger
).flatMapThrowing { negotiated -> Channel in

guard case .http1_1(let channel) = negotiated else {
preconditionFailure("Expected to create http/1.1 connections only for now")
}

// add the http1.1 channel handlers
let syncOperations = channel.pipeline.syncOperations
try syncOperations.addHTTPClientHandlers(leftOverBytesStrategy: .forwardBytes)

switch self.clientConfiguration.decompression {
case .disabled:
()
case .enabled(let limit):
let decompressHandler = NIOHTTPResponseDecompressor(limit: limit)
try syncOperations.addHandler(decompressHandler)
}

return channel
}
}

func makeChannel<Requester: HTTPConnectionRequester>(
requester: Requester,
connectionID: HTTPConnectionPool.Connection.ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension EmbeddedChannel {
channel: self,
connectionID: 1,
delegate: connectionDelegate,
configuration: .init(),
decompression: .disabled,
logger: logger
)

Expand Down
24 changes: 12 additions & 12 deletions Tests/AsyncHTTPClientTests/HTTP1ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: MockHTTP1ConnectionDelegate(),
configuration: .init(decompression: .enabled(limit: .ratio(4))),
decompression: .enabled(limit: .ratio(4)),
logger: logger
))

Expand All @@ -58,7 +58,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: MockHTTP1ConnectionDelegate(),
configuration: .init(decompression: .disabled),
decompression: .disabled,
logger: logger
))

Expand All @@ -82,7 +82,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: MockHTTP1ConnectionDelegate(),
configuration: .init(),
decompression: .disabled,
logger: logger
))
}
Expand All @@ -106,7 +106,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: $0,
connectionID: 0,
delegate: delegate,
configuration: .init(decompression: .disabled),
decompression: .disabled,
logger: logger
)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: XCTUnwrap(maybeChannel),
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(),
decompression: .disabled,
logger: logger
) }.wait())
guard let connection = maybeConnection else { return XCTFail("Expected to have a connection here") }
Expand Down Expand Up @@ -260,7 +260,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: XCTUnwrap(maybeChannel),
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(),
decompression: .disabled,
logger: logger
) }.wait())
guard let connection = maybeConnection else { return XCTFail("Expected to have a connection here") }
Expand Down Expand Up @@ -332,7 +332,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: XCTUnwrap(maybeChannel),
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(),
decompression: .disabled,
logger: logger
) }.wait())
guard let connection = maybeConnection else { return XCTFail("Expected to have a connection here") }
Expand Down Expand Up @@ -377,7 +377,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(decompression: .enabled(limit: .ratio(4))),
decompression: .enabled(limit: .ratio(4)),
logger: logger
))
guard let connection = maybeConnection else { return XCTFail("Expected to have a connection at this point.") }
Expand Down Expand Up @@ -442,7 +442,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(decompression: .enabled(limit: .ratio(4))),
decompression: .enabled(limit: .ratio(4)),
logger: logger
))
guard let connection = maybeConnection else { return XCTFail("Expected to have a connection at this point.") }
Expand Down Expand Up @@ -504,7 +504,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(decompression: .enabled(limit: .ratio(4))),
decompression: .enabled(limit: .ratio(4)),
logger: logger
))

Expand Down Expand Up @@ -539,7 +539,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(decompression: .enabled(limit: .ratio(4))),
decompression: .enabled(limit: .ratio(4)),
logger: logger
))
guard let connection = maybeConnection else { return XCTFail("Expected to have a connection at this point.") }
Expand Down Expand Up @@ -691,7 +691,7 @@ class HTTP1ConnectionTests: XCTestCase {
channel: channel,
connectionID: 0,
delegate: connectionDelegate,
configuration: .init(),
decompression: .disabled,
logger: logger
) }.wait())
guard let connection = maybeConnection else { return XCTFail("Expected to have a connection at this point") }
Expand Down
2 changes: 1 addition & 1 deletion Tests/AsyncHTTPClientTests/HTTP2ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HTTP2ConnectionTests: XCTestCase {
channel: embedded,
connectionID: 0,
delegate: TestHTTP2ConnectionDelegate(),
configuration: .init(),
decompression: .disabled,
logger: logger
).wait())
}
Expand Down