|
83 | 83 |
|
84 | 84 |
|
85 | 85 | (defn compress-handler [req] |
86 | | - (case (get-in req [:headers "accept-encoding"]) |
87 | | - "gzip" |
| 86 | + (case [(:uri req) (get-in req [:headers "accept-encoding"])] |
| 87 | + ["/" "gzip"] |
88 | 88 | {:body (util/gzip (util/utf8-bytes "foofoofoo")) |
89 | 89 | :headers {"content-encoding" "gzip"}} |
90 | | - "gzip, deflate" |
| 90 | + ["/" "gzip, deflate"] |
91 | 91 | {:body (util/gzip (util/utf8-bytes "foofoofoo")) |
92 | 92 | :headers {"content-encoding" "gzip"}} |
93 | | - "deflate" |
| 93 | + ["/" "deflate"] |
94 | 94 | {:body (util/deflate (util/utf8-bytes "barbarbar")) |
95 | 95 | :headers {"content-encoding" "deflate"}} |
| 96 | + ["/rfc1951" "deflate"] |
| 97 | + {:body (util/deflate (util/utf8-bytes "bazbazbaz") true) |
| 98 | + :headers {"content-encoding" "deflate"}} |
96 | 99 | {:body "foo"})) |
97 | 100 |
|
98 | 101 | (deftest compress-test |
99 | 102 | (let [client (client/wrap-decompression compress-handler)] |
100 | | - (is (= "foofoofoo" (-> {:headers {"accept-encoding" "gzip"}} |
| 103 | + (is (= "foofoofoo" (-> {:uri "/", :headers {"accept-encoding" "gzip"}} |
| 104 | + client |
| 105 | + :body |
| 106 | + util/utf8-string))) |
| 107 | + (is (= "barbarbar" (-> {:uri "/", :headers {"accept-encoding" "deflate"}} |
101 | 108 | client |
102 | 109 | :body |
103 | 110 | util/utf8-string))) |
104 | | - (is (= "barbarbar" (-> {:headers {"accept-encoding" "deflate"}} |
| 111 | + (is (= "bazbazbaz" (-> {:uri "/rfc1951", :headers {"accept-encoding" "deflate"}} |
105 | 112 | client |
106 | 113 | :body |
107 | 114 | util/utf8-string))) |
108 | 115 | (is (= "foo" (-> {} client :body))))) |
109 | 116 |
|
110 | 117 | (deftest coerce-compression |
111 | 118 | (let [client (client/wrap-coerce-compression compress-handler)] |
112 | | - (is (= "gzip" (-> {:headers {"accept-encoding" "gzip"}} |
| 119 | + (is (= "gzip" (-> {:uri "/", :headers {"accept-encoding" "gzip"}} |
113 | 120 | client |
114 | 121 | (get-in [:headers "content-encoding"])))) |
115 | | - (is (= "deflate" (-> {:headers {"accept-encoding" "deflate"}} |
| 122 | + (is (= "deflate" (-> {:uri "/", :headers {"accept-encoding" "deflate"}} |
116 | 123 | client |
117 | 124 | (get-in [:headers "content-encoding"])))) |
118 | | - (is (= "gzip" (-> {} |
| 125 | + (is (= "gzip" (-> {:uri "/"} |
119 | 126 | client |
120 | 127 | (get-in [:headers "content-encoding"])))) |
121 | | - (is (nil? (-> {:headers {"accept-encoding" "identity"}} |
| 128 | + (is (nil? (-> {:uri "/", :headers {"accept-encoding" "identity"}} |
122 | 129 | client |
123 | 130 | (get-in [:headers "content-encoding"])))))) |
124 | 131 |
|
|
0 commit comments