https://github.com/clj-commons/ring-gzip-middleware
GZIP your Ring responses
https://github.com/clj-commons/ring-gzip-middleware
Last synced: about 1 month ago
JSON representation
GZIP your Ring responses
- Host: GitHub
- URL: https://github.com/clj-commons/ring-gzip-middleware
- Owner: clj-commons
- License: mit
- Created: 2011-05-31T22:50:44.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2025-01-08T19:44:09.000Z (5 months ago)
- Last Synced: 2025-05-08T21:44:08.267Z (about 1 month ago)
- Language: Clojure
- Homepage:
- Size: 39.1 KB
- Stars: 45
- Watchers: 3
- Forks: 18
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
## ring-gzip-middleware
Gzips [Ring](http://github.com/ring-clojure/ring) responses for user agents
which can handle it.[](https://clojars.org/amalloy/ring-gzip-middleware)
[](https://cljdoc.org/d/amalloy/ring-gzip-middleware/CURRENT)
[](https://circleci.com/gh/clj-commons/ring-gzip-middleware)### Usage
Apply the Ring middleware function `ring.middleware.gzip/wrap-gzip` to
your Ring handler, typically at the top level (i.e. as the last bit of
middleware in a `->` form).### Installation
Add `[amalloy/ring-gzip-middleware "0.1.4"]` to your Leiningen dependencies.
### Compression of seq bodies
In JDK versions <=6, [`java.util.zip.GZIPOutputStream.flush()` does not actually
flush data compressed so
far](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4813885), which means
that every gzip response must be complete before any bytes hit the wire. While
of marginal importance when compressing static files and other resources that
are consumed in an all-or-nothing manner (i.e. virtually everything that is sent
in a Ring response), lazy sequences are impacted negatively by this. In
particular, long-polling or server-sent event responses backed by lazy
sequences, when gzipped under <=JDK6, must be fully consumed before the client
receives any data at all.So, _this middleware does not gzip-compress Ring seq response bodies unless the
JDK in use is 7+_, in which case it takes advantage of the new `flush`-ability
of `GZIPOutputStream` there.### License
Copyright (C) 2010 Michael Stephens and other contributors.
Distributed under an MIT-style license (see LICENSE for details).