Skip to content

Commit 6c83ee3

Browse files
authored
Handle request stream ending before receiving request end (#54)
Motivation: In #44, we introduced a `fatalError` in `HTTPRequestConcludingAsyncReader` when the request stream ends before the request end part is received. This is incorrect behaviour, and the server should not fatal error in this scenario. Modifications: Replaced the `fatalError` with a `throw`. Result: The server no longer fatal errors when the request stream ends before the request end part is received.
1 parent 88b16ef commit 6c83ee3

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

Sources/NIOHTTPServer/HTTPRequestConcludingAsyncReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public struct HTTPRequestConcludingAsyncReader: ConcludingAsyncReader, ~Copyable
9595
fatalError("Unexpectedly received a request head.")
9696

9797
case .none:
98-
fatalError("The stream unexpectedly ended before receiving a request end.")
98+
throw RequestBodyReadError.streamEndedBeforeReceivingRequestEnd
9999

100100
case .body(let element):
101101
bodyElement = element
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift HTTP Server open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift HTTP Server project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift HTTP Server project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
enum RequestBodyReadError: Error, CustomStringConvertible {
16+
case streamEndedBeforeReceivingRequestEnd
17+
18+
var description: String {
19+
switch self {
20+
case .streamEndedBeforeReceivingRequestEnd:
21+
"The request stream unexpectedly ended before receiving a request end part."
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)