@@ -207,15 +207,23 @@ struct HTTPRequestStateMachine {
207
207
208
208
case . running( . streaming, . receivingBody( let responseHead, _) ) ,
209
209
. 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.
210
217
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.
214
218
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.
215
223
return . wait
216
224
}
217
225
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
219
227
// we have received all necessary bytes. For this reason we forward the uncleanShutdown
220
228
// error to the user.
221
229
self . state = . failed( error)
0 commit comments