MCPcopy Create free account
hub / github.com/Effect-TS/effect / decompression

Function decompression

packages/effect/src/http/HttpMiddleware.ts:1029–1068  ·  view source on GitHub ↗
(
  options?: {
    /**
     * Maximum number of decompressed body bytes. Defaults to the
     * `MaxBodySize` reference, or 10 MiB when that is unset.
     */
    readonly maxDecompressedSize?: ByteSize.Input | undefined
  } | undefined
)

Source from the content-addressed store, hash-verified

1027 * @since 4.0.0
1028 */
1029export const decompression = (
1030 options?: {
1031 /**
1032 * Maximum number of decompressed body bytes. Defaults to the
1033 * `MaxBodySize` reference, or 10 MiB when that is unset.
1034 */
1035 readonly maxDecompressedSize?: ByteSize.Input | undefined
1036 } | undefined
1037): <E, R>(
1038 httpApp: Effect.Effect<HttpServerResponse, E, R>
1039) => Effect.Effect<HttpServerResponse, E, R | HttpServerRequest> => {
1040 const maxDecompressedSize = options?.maxDecompressedSize === undefined
1041 ? undefined
1042 : ByteSize.fromInputUnsafe(options.maxDecompressedSize)
1043 return <E, R>(
1044 httpApp: Effect.Effect<HttpServerResponse, E, R>
1045 ): Effect.Effect<HttpServerResponse, E, R | HttpServerRequest> =>
1046 Effect.withFiber((fiber) => {
1047 const request = Context.getUnsafe(fiber.context, HttpServerRequest)
1048 const contentEncoding = request.headers["content-encoding"]
1049 if (contentEncoding === undefined || !hasBody(request.method)) {
1050 return httpApp
1051 }
1052 const codings = decompressionInternal.parseContentEncoding(contentEncoding)
1053 if (codings === undefined) {
1054 return Effect.succeed(Response.empty({
1055 status: 415,
1056 headers: { "accept-encoding": "gzip, deflate" }
1057 }))
1058 }
1059 if (codings.length === 0) {
1060 return httpApp
1061 }
1062 return Effect.provideService(
1063 httpApp,
1064 HttpServerRequest,
1065 new decompressionInternal.DecompressedRequest(request, codings, maxDecompressedSize)
1066 )
1067 })
1068}
1069
1070const withVary = (response: HttpServerResponse): HttpServerResponse => {
1071 const vary = compressionInternal.varyWith(response.headers, "Accept-Encoding")

Callers

nothing calls this directly

Calls 3

hasBodyFunction · 0.90
getUnsafeMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected