Skip to content

Commit e7accb1

Browse files
committed
Add legacy x-gzip encoding (alias for gzip)
1 parent 4596e32 commit e7accb1

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎src/clj/ring/middleware/content_encoding.clj‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@
9393
(def default-encoder-weights
9494
"Weightings for which encoder to favor when the client has no preference.
9595
Higher values win out over lower ones."
96-
{"zstd" 5
97-
"br" 4
98-
"gzip" 3
96+
{"zstd" 6
97+
"br" 5
98+
"gzip" 4
99+
"x-gzip" 3
99100
"deflate" 2
100101
"identity" 1})
101102

@@ -105,13 +106,15 @@
105106
{"br" 50
106107
"deflate" 48
107108
"gzip" 48
109+
"x-gzip" 48
108110
"zstd" 50})
109111

110112
(def default-encoders
111113
"A map of encoder names to their respective default functions."
112114
{"br" (brotli-encoder)
113115
"deflate" (deflate-encoder)
114116
"gzip" (gzip-encoder)
117+
"x-gzip" (gzip-encoder)
115118
"zstd" (zstandard-encoder)})
116119

117120
(def default-status-codes

‎test/ring/middleware/content_encoding_test.clj‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
0 86 -79 23 74 11 0 0 0]
2929
(vec (.toByteArray out))))))
3030

31+
(deftest x-gzip-content-encoding-test
32+
(let [response (ce/content-encoding-response
33+
plain-response
34+
{:headers {"accept-encoding" "x-gzip"}})
35+
out (ByteArrayOutputStream.)]
36+
(p/write-body-to-stream (:body response) response out)
37+
(is (= {:status 200
38+
:headers {"Content-Type" "text/plain; charset=utf-8"
39+
"Content-Encoding" "x-gzip"}}
40+
(dissoc response :body)))
41+
(is (= [31 -117 8 0 0 0 0 0 0 -1 -13 72 -51 -55 -55 87 8 -49 47 -54 73 1
42+
0 86 -79 23 74 11 0 0 0]
43+
(vec (.toByteArray out))))))
44+
3145
(deftest gzip-content-encoding-params-test
3246
(let [response (ce/content-encoding-response
3347
{:status 200

0 commit comments

Comments
 (0)