Discussion:
Gzip responses
Robin Heggelund Hansen
2015-02-23 00:47:21 UTC
Permalink
I'm trying to get netty to gzip my responses to the client. This is what
I've tried so far.

(defn- pipeline-modifier [pipeline]
(doto pipeline
(.addLast "gzip" (HttpContentCompressor.))))


(defrecord Server [port routes db]
component/Lifecycle

(start [self]
(log/info "Starting server")
(if (:stop-fn self)
self
(let [handler (multimethod-handler db routes)]
(assoc self :stop-fn (http/start-server handler {:port port
:executor :none

:pipeline-transform pipeline-modifier})))))

(stop [self]
(log/info "Shutting down server")
(if-let [stop (:stop-fn self)]
(.close stop))
(dissoc self :stop-fn)))

What am I doing wrong?

By the way, I know I have been asking many questions lately. I just want to
end this question with some praise. Aleph is a really nice library, keep up
the good work!
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Zach Tellman
2015-02-23 23:15:20 UTC
Permalink
One option is to just use standard Ring middleware:
https://github.com/mikejs/ring-gzip-middleware

If you're set on using this approach, though, I'm pretty sure the issue
you're having is because of your use of `addLast()`, which puts the
compressor *after* the request handler. I'd guess, but haven't tested,
that using `(.addBefore "request-handler" "gzip" (HttpContentCompressor.))`
would work.

On Sun, Feb 22, 2015 at 4:47 PM, Robin Heggelund Hansen <
Post by Robin Heggelund Hansen
I'm trying to get netty to gzip my responses to the client. This is what
I've tried so far.
(defn- pipeline-modifier [pipeline]
(doto pipeline
(.addLast "gzip" (HttpContentCompressor.))))
(defrecord Server [port routes db]
component/Lifecycle
(start [self]
(log/info "Starting server")
(if (:stop-fn self)
self
(let [handler (multimethod-handler db routes)]
(assoc self :stop-fn (http/start-server handler {:port port
:executor :none
:pipeline-transform pipeline-modifier})))))
(stop [self]
(log/info "Shutting down server")
(if-let [stop (:stop-fn self)]
(.close stop))
(dissoc self :stop-fn)))
What am I doing wrong?
By the way, I know I have been asking many questions lately. I just want
to end this question with some praise. Aleph is a really nice library, keep
up the good work!
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robin Heggelund Hansen
2015-02-24 08:21:54 UTC
Permalink
I think I have tried addBefore with the same result. I'll try again when I
get home.
Of course, looking at the source of that ring handler, implementing my own
gzip function shouldn't be that harder either.

Thanks!
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ragnar Dahlén
2015-02-24 08:50:29 UTC
Permalink
I'm using this as :pipeline-transform

(defn add-http-compressor!
[^ChannelPipeline pipeline]
(doto pipeline
(.addBefore "request-handler" "deflater" (HttpContentCompressor.))))
Post by Robin Heggelund Hansen
I think I have tried addBefore with the same result. I'll try again when I
get home.
Of course, looking at the source of that ring handler, implementing my own
gzip function shouldn't be that harder either.
Thanks!
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robin Heggelund Hansen
2015-02-24 21:03:36 UTC
Permalink
Ragnar's example worked perfectly. Thank you both for good answers :)
Post by Ragnar Dahlén
I'm using this as :pipeline-transform
(defn add-http-compressor!
[^ChannelPipeline pipeline]
(doto pipeline
(.addBefore "request-handler" "deflater" (HttpContentCompressor.))))
Post by Robin Heggelund Hansen
I think I have tried addBefore with the same result. I'll try again when
I get home.
Of course, looking at the source of that ring handler, implementing my
own gzip function shouldn't be that harder either.
Thanks!
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mark Ingram
2016-10-12 08:09:22 UTC
Permalink
I noted that adding the HttpContentCompressor introduces a problem with
sending files as FileRegion (see:
https://github.com/netty/netty/issues/2260).

One way of supporting the mode would be the proposed:
https://github.com/ztellman/aleph/pull/277

And updated pipeline-transform:

(defn add-http-compressor!
[^ChannelPipeline pipeline]
(doto pipeline
(.addBefore "request-handler" "deflater" (HttpContentCompressor.))
(.addBefore "request-handler" "streamer" (ChunkedWriteHandler.))))
Post by Robin Heggelund Hansen
Ragnar's example worked perfectly. Thank you both for good answers :)
Post by Ragnar Dahlén
I'm using this as :pipeline-transform
(defn add-http-compressor!
[^ChannelPipeline pipeline]
(doto pipeline
(.addBefore "request-handler" "deflater" (HttpContentCompressor.))))
Post by Robin Heggelund Hansen
I think I have tried addBefore with the same result. I'll try again when
I get home.
Of course, looking at the source of that ring handler, implementing my
own gzip function shouldn't be that harder either.
Thanks!
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...