Skip to content

Commit 3e03472

Browse files
committed
Fix comment
1 parent df1217e commit 3e03472

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Diff for: Sources/AsyncHTTPClient/ConnectionPool/HTTPRequestStateMachine.swift

+12-4
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,23 @@ struct HTTPRequestStateMachine {
207207

208208
case .running(.streaming, .receivingBody(let responseHead, _)),
209209
.running(.endSent, .receivingBody(let responseHead, _)) where error as? NIOSSLError == .uncleanShutdown:
210+
// This code is only reachable for request and responses, which we expect to have a body.
211+
// We depend on logic from the HTTPResponseDecoder here. The decoder will emit an
212+
// HTTPResponsePart.end right after the HTTPResponsePart.head, for every request with a
213+
// CONNECT or HEAD method and every response with a 1xx, 204 or 304 response status.
214+
//
215+
// For this reason we only need to check the "content-length" or "transfer-encoding"
216+
// headers here to determine if we are potentially in an EOF terminated response.
210217

211-
// if we have already received the response head, the parser will ensure that we receive
212-
// the complete response. we can ignore this error. we might see a HTTPParserError very
213-
// soon.
214218
if responseHead.headers.contains(name: "content-length") || responseHead.headers.contains(name: "transfer-encoding") {
219+
// If we have already received the response head, the parser will ensure that we
220+
// receive a complete response, if the content-length or transfer-encoding header
221+
// was set. In this case we can ignore the NIOSSLError.uncleanShutdown. We will see
222+
// a HTTPParserError very soon.
215223
return .wait
216224
}
217225

218-
// if the response is EOF terminated, we need to rely on a clean tls shutdown to be sure
226+
// If the response is EOF terminated, we need to rely on a clean tls shutdown to be sure
219227
// we have received all necessary bytes. For this reason we forward the uncleanShutdown
220228
// error to the user.
221229
self.state = .failed(error)

0 commit comments

Comments
 (0)