Skip to content

Commit 7ee281d

Browse files
authored
Make a few cleanups to the dripping download handler (#295)
Motivation The dripping download handler should aim to be as efficient as possible. Modifications Avoid creating a second HTTPFields object when we are sending content-length in the response. Avoid an extra flush on the response head. Results Better performance behaviour.
1 parent d5578e7 commit 7ee281d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/NIOHTTPResponsiveness/HTTPDrippingDownloadHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ public final class HTTPDrippingDownloadHandler: ChannelDuplexHandler {
140140

141141
// If the length isn't too big, let's include a content length header
142142
if case (let contentLength, false) = self.size.multipliedReportingOverflow(by: self.count) {
143-
head.headerFields = HTTPFields(dictionaryLiteral: (.contentLength, "\(contentLength)"))
143+
head.headerFields[.contentLength] = "\(contentLength)"
144144
}
145145

146-
context.writeAndFlush(self.wrapOutboundOut(.head(head)), promise: nil)
146+
context.write(self.wrapOutboundOut(.head(head)), promise: nil)
147147
self.phase = .dripping(
148148
DrippingState(
149149
chunksLeft: self.count,

0 commit comments

Comments
 (0)