Removed “Connection” headers (#26)

This commit is contained in:
Fabian Fett
2020-03-09 17:49:39 +01:00
committed by GitHub
parent ddee38c367
commit df4e247910
2 changed files with 29 additions and 6 deletions
+4 -1
View File
@@ -125,7 +125,10 @@ internal final class HTTPHandler: ChannelInboundHandler {
func writeResponse(context: ChannelHandlerContext, status: HTTPResponseStatus, headers: [(String, String)]? = nil, body: String? = nil) {
var headers = HTTPHeaders(headers ?? [])
headers.add(name: "Content-Length", value: "\(body?.utf8.count ?? 0)")
headers.add(name: "Connection", value: self.keepAlive ? "keep-alive" : "close")
if !self.keepAlive {
// We only need to add a "Connection" header if we really want to close the connection
headers.add(name: "Connection", value: "close")
}
let head = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: status, headers: headers)
context.write(wrapOutboundOut(.head(head))).whenFailure { error in