mirror of
https://github.com/apple/swift-nio
synced 2026-11-30 05:28:44 +00:00
HTTP1 example server: don't crash on empty file served (#962)
Motivation:
The file-io implementation in the example HTTP1 server just crashed on
empty file ;).
Modifications:
- fix the crash
- add integration test
Result:
fewer crashes
(cherry picked from commit c90b159b4f)
This commit is contained in:
1 parent
0bcc08d85f
commit
c07fea1aa5
2 files changed
+10
-3
No files matched your search
@@ -333,6 +333,10 @@ private final class HTTPHandler: ChannelInboundHandler {
|
||||
case .nonblockingFileIO:
|
||||
var responseStarted = false
|
||||
let response = responseHead(request: request, fileRegion: region)
|
||||
if region.readableBytes == 0 {
|
||||
responseStarted = true
|
||||
context.write(self.wrapOutboundOut(.head(response)), promise: nil)
|
||||
}
|
||||
return self.fileIO.readChunked(fileRegion: region,
|
||||
chunkSize: 32 * 1024,
|
||||
allocator: context.channel.allocator,
|
||||
|
||||
Reference in new issue
Block a user