Skip to content
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
8 changes: 8 additions & 0 deletions Sources/NIOHTTPClient/HTTPHandler.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -286,6 +286,8 @@ internal class TaskHandler<T: HTTPClientResponseDelegate>: ChannelInboundHandler
headers.add(name: "Host", value: request.host)
}

headers.add(name: "Connection", value: "close")

do{
try headers.validate(body: request.body)
} catch{
Expand DownExpand Up@@ -321,6 +323,11 @@ internal class TaskHandler<T: HTTPClientResponseDelegate>: ChannelInboundHandler

self.state = .sent
self.delegate.didTransmitRequestBody(task: self.task)

let channel = context.channel
self.promise.futureResult.whenComplete{_ in
channel.close(promise: nil)
}
}

func channelRead(context: ChannelHandlerContext, data: NIOAny){
Expand All@@ -346,6 +353,7 @@ internal class TaskHandler<T: HTTPClientResponseDelegate>: ChannelInboundHandler
case .redirected(let head, let redirectURL):
self.state = .end
self.redirectHandler?.redirect(status: head.status, to: redirectURL, promise: self.promise)
context.close(promise: nil)
default:
self.state = .end
do{
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOHTTPClientTests/SwiftNIOHTTPTests.swift
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,6 +55,7 @@ class SwiftHTTPTests: XCTestCase{
head.headers.add(name: "X-Test-Header", value: "X-Test-Value")
head.headers.add(name: "Host", value: "localhost")
head.headers.add(name: "Content-Length", value: "4")
head.headers.add(name: "Connection", value: "close")
XCTAssertEqual(HTTPClientRequestPart.head(head), recorder.writes[0])
var buffer = ByteBufferAllocator().buffer(capacity: 4)
buffer.writeString("1234")
Expand Down