Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.9 KB

File metadata and controls

56 lines (38 loc) · 1.9 KB

Ring-Content-Encoding Build Status

Ring middleware for adding modern response compression to your web application. It supports Brotli, Deflate, GZip and ZStandard content encoding, and has sensible defaults for when to apply compression and when not avoid it (such as for image formats).

Note

Many reverse proxies and CDNs will handle content encoding for you. However, you may want more control over how content encoding is handled, or you may not be using a reverse proxy at all. This is where this middleware comes in useful.

Installation

Add the following dependency to your deps.edn file:

org.ring-clojure/ring-content-encoding {:mvn/version "0.1.0"}

Or to your Leiningen project file:

[org.ring-clojure/ring-content-encoding "0.1.0"]

Usage

Use the wrap-content-encoding function to add support for various types of content encoding (i.e. compression).

(require '[ring.middleware.content-encoding :refer [wrap-content-encoding]])

(defn handler [_request]
  {:status  200
   :headers {"Content-Type"   "text/plain; charset=utf-8"
             "Content-Length" "55"}
   :body    "This text will be compressed if the client supports it."})

(def app
  (wrap-content-encoding handler))

Documentation

License

Copyright © 2026 James Reeves

Released under the MIT license.