Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions Sources/AsyncHTTPClient/HTTPHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,10 @@ extension HTTPClient {

func fail<Delegate: HTTPClientResponseDelegate>(with error: Error, delegateType: Delegate.Type) {
if let connection = self.connection {
connection.channel.close(promise: nil)
self.releaseAssociatedConnection(delegateType: delegateType, closing: true)
.whenSuccess {
self.promise.fail(error)
connection.channel.close(promise: nil)
}
}
}
Expand Down Expand Up @@ -729,7 +729,7 @@ extension TaskHandler: ChannelDuplexHandler {
try headers.validate(method: request.method, body: request.body)
} catch {
promise?.fail(error)
context.fireErrorCaught(error)
self.failTaskAndNotifyDelegate(error: error, self.delegate.didReceiveError)
self.state = .end
return
}
Expand Down
1 change: 1 addition & 0 deletions Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ extension HTTPClientTests {
("testRacePoolIdleConnectionsAndGet", testRacePoolIdleConnectionsAndGet),
("testAvoidLeakingTLSHandshakeCompletionPromise", testAvoidLeakingTLSHandshakeCompletionPromise),
("testAsyncShutdown", testAsyncShutdown),
("testValidationErrorsAreSurfaced", testValidationErrorsAreSurfaced),
]
}
}
19 changes: 18 additions & 1 deletion Tests/AsyncHTTPClientTests/HTTPClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ class HTTPClientTests: XCTestCase {
}
}

func testAsyncShutdown() {
func testAsyncShutdown() throws {
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))
let promise = self.clientGroup.next().makePromise(of: Void.self)
self.clientGroup.next().execute {
Expand All @@ -1678,4 +1678,21 @@ class HTTPClientTests: XCTestCase {
}
XCTAssertNoThrow(try promise.futureResult.wait())
}

func testValidationErrorsAreSurfaced() throws {
let httpBin = HTTPBin()
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))
defer {
XCTAssertNoThrow(try httpClient.syncShutdown())
XCTAssertNoThrow(try httpBin.shutdown())
}

let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get", method: .TRACE, body: .stream { _ in
httpClient.eventLoopGroup.next().makeSucceededFuture(())
})
let runningRequest = httpClient.execute(request: request)
XCTAssertThrowsError(try runningRequest.wait()) { error in
XCTAssertEqual(HTTPClientError.traceRequestWithBody, error as? HTTPClientError)
}
}
}