|
1 | 1 | ## ring-gzip-middleware
|
2 | 2 |
|
3 |
| -Gzips [Ring](http://github.com/mmcgrana/ring) responses for user agents which can handle it. |
| 3 | +Gzips [Ring](http://github.com/ring-clojure/ring) responses for user agents |
| 4 | +which can handle it. |
4 | 5 |
|
5 | 6 | ### Usage
|
6 | 7 |
|
7 | 8 | Apply the Ring middleware function `ring.middleware.gzip/wrap-gzip` to
|
8 | 9 | your Ring handler, typically at the top level (i.e. as the last bit of
|
9 | 10 | middleware in a `->` form).
|
10 | 11 |
|
11 |
| - |
12 | 12 | ### Installation
|
13 | 13 |
|
14 | 14 | Add `[amalloy/ring-gzip-middleware "0.1.2"]` to your Leingingen dependencies.
|
15 | 15 |
|
| 16 | +### Compression of seq bodies |
| 17 | + |
| 18 | +In JDK versions <=6, [`java.util.zip.GZIPOutputStream.flush()` does not actually |
| 19 | +flush data compressed so |
| 20 | +far](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4813885), which means |
| 21 | +that every gzip response must be complete before any bytes hit the wire. While |
| 22 | +of marginal importance when compressing static files and other resources that |
| 23 | +are consumed in an all-or-nothing manner (i.e. virtually everything that is sent |
| 24 | +in a Ring response), lazy sequences are impacted negatively by this. In |
| 25 | +particular, long-polling or server-sent event responses backed by lazy |
| 26 | +sequences, when gzipped under <=JDK6, must be fully consumed before the client |
| 27 | +receives any data at all. |
| 28 | + |
| 29 | +So, _this middleware does not gzip-compress Ring seq response bodies unless the |
| 30 | +JDK in use is 7+_, in which case it takes advantage of the new `flush`-ability |
| 31 | +of `GZIPOutputStream` there. |
| 32 | + |
16 | 33 | ### License
|
17 | 34 |
|
18 | 35 | Copyright (C) 2010 Michael Stephens and other contributors.
|
|
0 commit comments