(
compression: HttpPlatform["Service"]["compression"],
acceptEncoding: string | undefined,
response: HttpServerResponse
)
| 486 | zstd: { level: levels.zstd } |
| 487 | } |
| 488 | const transform = ( |
| 489 | compression: HttpPlatform["Service"]["compression"], |
| 490 | acceptEncoding: string | undefined, |
| 491 | response: HttpServerResponse |
| 492 | ): Effect.Effect<HttpServerResponse> => { |
| 493 | if ( |
| 494 | response.status < 200 || |
| 495 | response.status === 204 || |
| 496 | response.status === 206 || |
| 497 | response.status === 304 |
| 498 | ) { |
| 499 | return Effect.succeed(response) |
| 500 | } |
| 501 | const currentEncoding = response.headers["content-encoding"] |
| 502 | if (currentEncoding !== undefined) { |
| 503 | return Effect.succeed( |
| 504 | currentEncoding.trim().toLowerCase() === "identity" |
| 505 | ? Response.removeHeader(response, "content-encoding") |
| 506 | : response |
| 507 | ) |
| 508 | } |
| 509 | const body = response.body |
| 510 | if (body._tag === "Empty" || body._tag === "FormData") { |
| 511 | return Effect.succeed(response) |
| 512 | } |
| 513 | const cacheControl = response.headers["cache-control"] |
| 514 | if (cacheControl !== undefined && noTransformRegex.test(cacheControl)) { |
| 515 | return Effect.succeed(response) |
| 516 | } |
| 517 | const contentType = response.headers["content-type"] ?? body.contentType |
| 518 | if (contentType === undefined || !compressible(contentType)) { |
| 519 | return Effect.succeed(response) |
| 520 | } |
| 521 | const algorithm = compressionInternal.negotiate(acceptEncoding, preferred, compression.algorithms) |
| 522 | if (algorithm === undefined) { |
| 523 | return Effect.succeed(withVary(response)) |
| 524 | } |
| 525 | const contentLength = body.contentLength ?? contentLengthHeader(response.headers) |
| 526 | if (contentLength !== undefined && contentLength < minSize) { |
| 527 | return Effect.succeed(withVary(response)) |
| 528 | } |
| 529 | return compression.compressResponse(response, algorithm, levelOptions[algorithm]) |
| 530 | } |
| 531 | return <E, R>( |
| 532 | httpApp: Effect.Effect<HttpServerResponse, E, R> |
| 533 | ): Effect.Effect<HttpServerResponse, E, R | HttpServerRequest | HttpPlatform> => |
no test coverage detected