scoop:scoop.http.server:0.1.0
src/decompression/options.scoop
Selected production source · src/decompression/options.scoop
1
package scoop.http.server3
import scoop.compression.CompressionFormat5
/** Request content coding policy, installed before choosing a body consumer. */6
public class RequestDecompressionOptions internal constructor(7
allowedFormats: List<CompressionFormat> =8
[9
CompressionFormat.Gzip,10
CompressionFormat.Zlib,11
CompressionFormat.Brotli,12
CompressionFormat.Zstd13
],14
/** Maximum number of actual coding layers; identity does not count. */15
public val maxLayers: Long = 2L,16
/** Maximum output of each decoding layer, including the final plaintext view. */17
public val decodedBodyLimit: Long? = Some(8388608L),18
/** Maximum zstd window; no window option is passed to other formats. */19
public val maxWindowBytes: Long? = Some(8388608L),20
/** Bounded input buffering for each decoder. */21
public val bufferSize: Long = 8192L22
) {23
/** A snapshot of the permitted wire formats. */24
public val allowedFormats: Array<CompressionFormat> = allowedFormats.toArray()25
init {26
if (27
maxLayers <28
0L ||29
bufferSize <=30
0L ||31
(present(decodedBodyLimit) && decodedBodyLimit!! < 0L) ||32
(present(maxWindowBytes) && maxWindowBytes!! <= 0L)33
)34
throw IllegalArgumentException(Some("invalid request decompression bounds"))35
val seen = ArrayList<CompressionFormat>()36
for (format in allowedFormats) {37
if (format == CompressionFormat.RawDeflate)38
throw IllegalArgumentException(Some("HTTP deflate requires the zlib wrapper"))39
for (previous in seen)40
if (previous == format)41
throw IllegalArgumentException(Some("duplicate request content coding"))42
seen.add(format)43
}44
}45
}47
/** Configures the downstream request body without reading input or sending 100 Continue. */48
public fun requestDecompression(49
options: RequestDecompressionOptions = requestDecompressionOptions()50
): HttpMiddleware =51
suspend {52
ctx, next ->53
ctx.requestJob.ensureActive()54
ctx.request.body.configureDecoding(options)55
next()56
}58
/** Facts about the selected body view; the original request head remains unchanged. */59
public class HttpRequestBodyView internal constructor(60
/** Removed coding names in original field order, excluding identity. */61
public val decodedEncodings: Array<String>,62
/** Original Content-Length for an unchanged view; None after actual decoding. */63
public val contentLength: Long?64
)