Response compression for the Website service (#7)

This PR contains the work done to add response compression to the Website service by registering the `ResponseCompressionMiddleware` middleware so responses are compressed when the client advertises support and the body exceeds a minimum size.

To provide further details about the work done:

* Added the **HummingbirdCompression** package dependency.
* Integrated the `ResponseCompressionMiddleware` middleware into the router, ahead of the not-found and static file middleware.
* Made the `minimum-response-size-to-compress` threshold configurable, with a default.

Reviewed-on: rock-n-code/loud-amsterdam#7
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit is contained in:
2026-06-28 06:15:05 +00:00
committed by javier
parent 6c1a0f713b
commit 7c18cd9ec0
6 changed files with 68 additions and 6 deletions
+27
View File
@@ -71,6 +71,33 @@ struct AppTests {
}
}
@Test
func `response to be compressed when the client supports it`() async throws {
try await app.test(.router) { client in
try await client.execute(
uri: "/",
method: .get,
headers: [.acceptEncoding: "gzip"]
) { response in
#expect(response.status == .ok)
#expect(response.headers[.contentEncoding] == "gzip")
}
}
}
@Test
func `response to not be compressed when the client does not support it`() async throws {
try await app.test(.router) { client in
try await client.execute(
uri: "/",
method: .get
) { response in
#expect(response.status == .ok)
#expect(response.headers[.contentEncoding] == nil)
}
}
}
@Test
func `error page to be served when not found`() async throws {
try await app.test(.router) { client in