From 91dbc92685e2b19521306985467012efebbc6b69 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Mon, 6 May 2024 08:05:29 +0100 Subject: [PATCH] Add content-length header if we pass in a body to router test framework (#434) --- Sources/HummingbirdTesting/RouterTestFramework.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/HummingbirdTesting/RouterTestFramework.swift b/Sources/HummingbirdTesting/RouterTestFramework.swift index 2e40a88b4..8b64e033c 100644 --- a/Sources/HummingbirdTesting/RouterTestFramework.swift +++ b/Sources/HummingbirdTesting/RouterTestFramework.swift @@ -97,6 +97,10 @@ struct RouterTestFramework: ApplicationTestFramework w func executeRequest(uri: String, method: HTTPRequest.Method, headers: HTTPFields, body: ByteBuffer?) async throws -> TestResponse { return try await withThrowingTaskGroup(of: TestResponse.self) { group in + var headers = headers + if let contentLength = body.map(\.readableBytes) { + headers[.contentLength] = String(describing: contentLength) + } let (stream, source) = RequestBody.makeStream() let request = Request( head: .init(method: method, scheme: "http", authority: "localhost", path: uri, headerFields: headers),