class
Amber::Pipe::Compression
- Amber::Pipe::Compression
- Amber::Pipe::Base
- Reference
- Object
Overview
Gzips or deflates a pipeline's responses for clients that accept it.
The bytes on the wire match Crystal's HTTP::CompressHandler at the same
level. The difference is where the compressor lives: each zlib stream
(about 270 KB of state and buffers) comes from malloc, outside the
garbage-collected heap, and goes back to a small pool when the response
closes. HTTP::CompressHandler allocates that state from the collected
heap for every response, which made it the largest allocation in a
generated app.
A request with a Range header is answered uncompressed, because a
byte range refers to the uncompressed body. Every response through the
pipe carries Vary: Accept-Encoding. A response that already has a
Content-Encoding (for example a pre-gzipped page from the page cache)
passes through unchanged.
pipeline :web do
plug Amber::Pipe::Compression.new
plug Amber::Pipe::Error.new
end
level is the zlib level, 0 to 9, or -1 for zlib's default (6). idle_compressors is how many compressors the pool keeps between responses; one more in use at once is created and then released.
Defined in:
amber/pipes/compression.cramber/pipes/compression/compressed_output.cr
amber/pipes/compression/deflater.cr
Constant Summary
-
DEFAULT_IDLE_COMPRESSORS =
4 -
How many compressors the pool keeps between responses by default.
Constructors
Instance Method Summary
-
#call(context : HTTP::Server::Context)
Execution of this handler.
-
#pool : DeflaterPool
The compressors this pipe lends to its responses.
Instance methods inherited from class Amber::Pipe::Base
call(context : HTTP::Server::Context)
call
Constructor Detail
Instance Method Detail
Execution of this handler.