Skip to content

Commit

Permalink
Update content-length header on setting response body
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Apr 23, 2024
1 parent 32a724e commit 12f5696
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/HummingbirdCore/Response/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 12f5696

Please sign in to comment.