From 12f56966bb1c580319d2d7a7d30707c0cb5f4803 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 23 Apr 2024 07:52:16 +0100 Subject: [PATCH] Update content-length header on setting response body --- Sources/HummingbirdCore/Response/Response.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/HummingbirdCore/Response/Response.swift b/Sources/HummingbirdCore/Response/Response.swift index f6d143576..83ba8eeca 100644 --- a/Sources/HummingbirdCore/Response/Response.swift +++ b/Sources/HummingbirdCore/Response/Response.swift @@ -17,7 +17,13 @@ import HTTPTypes /// Holds all the required to generate a HTTP Response public struct Response: Sendable { public var head: HTTPResponse - public var body: ResponseBody + public var body: ResponseBody { + didSet { + if let contentLength = body.contentLength { + self.head.headerFields[.contentLength] = String(describing: contentLength) + } + } + } public init(status: HTTPResponse.Status, headers: HTTPFields = .init(), body: ResponseBody = .init()) { self.head = .init(status: status, headerFields: headers)