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)