This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-08
Channels
- # asami (7)
- # aws (2)
- # babashka (21)
- # beginners (602)
- # calva (8)
- # cider (11)
- # clj-kondo (10)
- # cljfx (1)
- # clojure (177)
- # clojure-europe (43)
- # clojure-nl (3)
- # clojure-taiwan (2)
- # clojure-uk (45)
- # clojurescript (31)
- # depstar (8)
- # figwheel-main (2)
- # fulcro (12)
- # hugsql (2)
- # java (1)
- # jobs (2)
- # meander (1)
- # missionary (1)
- # off-topic (67)
- # other-languages (1)
- # pathom (212)
- # polylith (4)
- # rdf (1)
- # re-frame (10)
- # reagent (12)
- # reitit (28)
- # reveal (3)
- # shadow-cljs (21)
- # spacemacs (7)
- # sql (5)
- # tools-deps (12)
- # vim (1)
Hi sorry if question is too simple, but what would be proper middleware to decompres requests which have content encoding: gzip
? I thought it should be handled automatically but it looks like [muuntaja.format.json/decoder]
is called before it gets decompressed
https://github.com/clj-commons/ring-gzip-middleware or one of others gzip middlewares is needed I think most projects handle this in nginx or such loadbalancer
Or that one looks to be only about compressing responses
It should happen automatically, but I think you need to tell reitit to expect gzip as a content encoding.
Let me see if I can find where that’s specified
Hmm, I may be confusing that with something else, still digging
I can't even find mention of gzip in requests in reitit repo so I wonder if maybe this should be handled by web server
Are you using jetty as your web server engine?
:thumbsup: It looks like that’s the bit that needs to be configured to handle gzip encoding.
just need to check that danielsz/system jetty component allows passing of configurator flag 😄
unfortunately it looks like it doesn't work, switched to http kit server and the same problem persists
https://github.com/clj-commons/ring-gzip-middleware or one of others gzip middlewares is needed I think most projects handle this in nginx or such loadbalancer
Yeah. No idea how it works on the requests usually, never encountered problems.
Maybe a tangential question, but why are your incoming requests using gzip? Are they that large? A file upload would be, but file uploads usually use a different mechanism.
Looks like clients normally don't send compressed data as they can't know if server supports it.
You could implment this in a middleware yourself. Just make sure it runs before Muuntaja, and wrap the req body inputstream in GZIPInputStream
.
thanks for help. I will probably need to settle on writting middleware as you mentioned albeit I would like to avoid it as custom code is always a higher chance of bugs 😄
for posterity, tested such simple middleware fn and it works:
(defn gzip-wrap [handler]
(fn [request]
(if (= (get-in request [:headers "content-encoding"]) "gzip")
(let [gzip-body (GZIPInputStream. (:body request))
response (handler (assoc request :body gzip-body))]
(.close gzip-body)
response)
(handler request))))
with-open saves a few lines: (with-open [gzip-body (GZIPInputStream. (:body request))] (handler (assoc request :body gzip-body)))