Skip to content

Add HTTP2Connection #401

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 12 commits into from
Jul 22, 2021
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
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let package = Package(
dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
.product(name: "NIOHTTPCompression", package: "swift-nio-extras"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
/// the currently executing request
private var request: HTTPExecutableRequest? {
didSet {
if let request = request {
var requestLogger = request.logger
if let newRequest = self.request {
var requestLogger = newRequest.logger
requestLogger[metadataKey: "ahc-connection-id"] = "\(self.connection.id)"
self.logger = requestLogger

if let idleReadTimeout = newRequest.idleReadTimeout {
self.idleReadTimeoutStateMachine = .init(timeAmount: idleReadTimeout)
}
} else {
self.logger = self.backgroundLogger
self.idleReadTimeoutStateMachine = nil
}
}
}
Expand Down Expand Up @@ -100,7 +105,7 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
}

func channelRead(context: ChannelHandlerContext, data: NIOAny) {
let httpPart = unwrapInboundIn(data)
let httpPart = self.unwrapInboundIn(data)

self.logger.trace("HTTP response part received", metadata: [
"ahc-http-part": "\(httpPart)",
Expand All @@ -121,6 +126,17 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
self.run(action, context: context)
}

func errorCaught(context: ChannelHandlerContext, error: Error) {
self.logger.trace("Error caught", metadata: [
"error": "\(error)",
])

let action = self.state.errorHappened(error)
self.run(action, context: context)
}

// MARK: Channel Outbound Handler

func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
assert(self.request == nil, "Only write to the ChannelHandler if you are sure, it is idle!")
let req = self.unwrapOutboundIn(data)
Expand All @@ -145,15 +161,6 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
self.run(action, context: context)
}

func errorCaught(context: ChannelHandlerContext, error: Error) {
self.logger.trace("Error caught", metadata: [
"error": "\(error)",
])

let action = self.state.errorHappened(error)
self.run(action, context: context)
}

func triggerUserOutboundEvent(context: ChannelHandlerContext, event: Any, promise: EventLoopPromise<Void>?) {
switch event {
case HTTPConnectionEvent.cancelRequest:
Expand Down Expand Up @@ -246,7 +253,6 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {

let oldRequest = self.request!
self.request = nil
self.idleReadTimeoutStateMachine = nil

switch finalAction {
case .close:
Expand All @@ -265,7 +271,6 @@ final class HTTP1ClientChannelHandler: ChannelDuplexHandler {
// see comment in the `succeedRequest` case.
let oldRequest = self.request!
self.request = nil
self.idleReadTimeoutStateMachine = nil

switch finalAction {
case .close:
Expand Down
Loading