Profiles·Public

compression

semver>=1.7.0 <2.0.0postconditions7functions2last verified2026-04-16coverage score100%

Postconditions — what we check

  • compression · filter-throws
    error
    WhenThe filter option function throws an error when called during a request
    ThrowsError propagated to Express error handler via next(err)
    Required handlingIf providing a custom filter function, it MUST NOT throw — errors inside filter are not caught internally and will crash the request pipeline. Wrap custom filter logic in try-catch and return true/false safely.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1]
  • compression · downstream-error
    error
    WhenAn error occurs in the response stream during compression
    ThrowsError emitted on the response stream
    Required handlingCaller MUST attach an Express error handler (app.use with 4-argument function) to catch stream errors propagated by the middleware.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1]
  • compression · below-threshold
    info
    WhenResponse body size is below the configured threshold (default: 1kb)
    ReturnsResponse is sent uncompressed; no compression is applied
    Required handlingNo action required — use the returned value as needed.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1]
  • compression · not-compressible
    info
    WhenContent-Type is not compressible (per compressible module) and no custom filter is set
    ReturnsResponse is passed through uncompressed
    Required handlingNo action required — use the returned value as needed.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1]
  • compression · compression-applied
    info
    WhenResponse is compressible, above threshold, and client supports compression
    ReturnsResponse body is compressed (gzip or deflate) and Content-Encoding header is set
    Required handlingNo action required — use the returned value as needed.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1]
  • compression · zlib-stream-unhandled-error
    error
    WhenThe internal zlib compression stream emits an 'error' event (e.g., memory allocation failure, invalid zlib parameters, or a rare compression fault)
    ThrowsUncaught exception — the zlib stream error is emitted with no .on('error') listener attached by compression middleware, causing the Node.js process to throw an uncaught exception (or unhandledRejection) and potentially crash.
    Required handlingCallers using compression() middleware SHOULD attach an Express error handler (app.use with 4-argument signature) and/or a global process.on('uncaughtException') handler. The middleware does not protect against internal zlib stream errors. For production use, a process supervisor (pm2, systemd) must restart the process after such a crash.
    costhighin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[2][3]
  • compression · sse-missing-flush
    error
    WhenServer-Sent Events (SSE) or any streaming response uses compression() middleware and writes data with res.write() but does NOT call res.flush() after each write
    ReturnsCompressed data is buffered in the zlib stream and NOT immediately delivered to the client. SSE clients receive no events (or very delayed batched events) until the zlib buffer fills.
    Required handlingAny SSE or streaming endpoint using compression() MUST call res.flush() after each res.write() call to force zlib to flush its buffer and deliver the compressed chunk immediately. Alternative: set Cache-Control: no-transform to bypass compression for SSE endpoints.
    costmediumin proddelayed failureusers seedegraded performancevisibilitysilent
    Sources[1]

Sources

Every postcondition cites at least one of these. Numbered to match the footnotes above.

  1. [1]github.com/expressjs/compressionhttps://github.com/expressjs/compression/blob/master/README.md
  2. [2]github.com/expressjs/compressionhttps://github.com/expressjs/compression/blob/master/index.js
  3. [3]nodejs.org/api/errors.htmlhttps://nodejs.org/api/errors.html#class-error
Need a different package?
Request a profile