Skip to content

Commit d693dae

Browse files
committed
Put jdk7 check into a delay, ensure it doesn't run AOT-time, etc
1 parent fa7f9d7 commit d693dae

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/ring/middleware/gzip.clj

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
; only available on JDK7
1313
(def ^:private flushable-gzip?
14-
(->> (clojure.reflect/reflect GZIPOutputStream)
15-
:members
16-
(some (comp '#{[java.io.OutputStream boolean]} :parameter-types))))
14+
(delay (->> (clojure.reflect/reflect GZIPOutputStream)
15+
:members
16+
(some (comp '#{[java.io.OutputStream boolean]} :parameter-types)))))
1717

1818
; only proxying here so we can specialize io/copy (which ring uses to transfer
1919
; InputStream bodies to the servlet response) for reading from the result of
@@ -38,8 +38,9 @@
3838
(defn piped-gzipped-input-stream [in]
3939
(let [pipe-in (piped-gzipped-input-stream*)
4040
pipe-out (PipedOutputStream. pipe-in)]
41-
(future ; new thread to prevent blocking deadlock
42-
(with-open [out (if flushable-gzip?
41+
; separate thread to prevent blocking deadlock
42+
(future
43+
(with-open [out (if @flushable-gzip?
4344
(GZIPOutputStream. pipe-out true)
4445
(GZIPOutputStream. pipe-out))]
4546
(if (seq? in)
@@ -66,7 +67,7 @@
6667
(not (get-in resp [:headers "Content-Encoding"]))
6768
(or
6869
(and (string? body) (> (count body) 200))
69-
(and (seq? body) flushable-gzip?)
70+
(and (seq? body) @flushable-gzip?)
7071
(instance? InputStream body)
7172
(instance? File body)))
7273
(let [accepts (get-in req [:headers "accept-encoding"] "")

test/ring/middleware/gzip_test.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
:headers {}}))
5353
resp (app (accepting "gzip"))]
5454
(is (= 200 (:status resp)))
55-
(if @#'ring.middleware.gzip/flushable-gzip?
55+
(if @@#'ring.middleware.gzip/flushable-gzip?
5656
(do
5757
(println "Running on JDK7+, testing gzipping of seq response bodies.")
5858
(is (= "gzip" (encoding resp)))

0 commit comments

Comments
 (0)