This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-04
Channels
- # aleph (23)
- # announcements (1)
- # babashka (21)
- # beginners (70)
- # biff (3)
- # cider (8)
- # clj-kondo (45)
- # clj-yaml (9)
- # clojure (69)
- # clojure-europe (82)
- # clojure-nl (1)
- # clojure-norway (2)
- # clojurescript (34)
- # conjure (19)
- # core-typed (6)
- # cursive (2)
- # events (5)
- # fulcro (55)
- # honeysql (1)
- # integrant (12)
- # jobs (1)
- # lsp (124)
- # malli (10)
- # meander (1)
- # off-topic (26)
- # polylith (8)
- # reagent (7)
- # releases (1)
- # remote-jobs (1)
- # sci (2)
- # shadow-cljs (19)
- # squint (5)
- # vim (17)
- # xtdb (31)
Hi, I have an app which uses aleph (0.4.5-alpha) + manifold (0.1.7-alpha6) streams to serve SSE. I noticed that response that is served is not being compressed, and given there is a lot of data it goes pretty slow. So I wonder if there is an easy way to enable the compression or I need to do it manually, and if the latter, what is the best way to do it. The code looks something like this -
(defn sse-handler
[req]
(let [event-stream (s/stream)
keep-alive-stream (s/periodically timeout (fn [] ":keepalive\n"))]
(s/connect keep-alive-stream event-stream {:timeout timeout})
(s/put! event-stream (str "data: " (write-transit (export-data)}) "\n\n"))
{:status 200
:headers {"Content-Type" "text/event-stream; charset=utf-8"
"Access-Control-Allow-Origin" "*"
"Cache-Control" "no-cache"}
:body event-stream}))
I've enabled :compression? true
in aleph http server and it looks like the usual responses are being indeed compressed but not SSE.
Thanks in advance.:compression? true
should apply here, too. Perhaps your SSE client request doesn't include the proper Accept-Encoding
header?
Nice idea with the keep-alive-stream
btw 🙂 Although it's a bit suboptimal in that it also sends keepalive messages even when regular events are being sent during the timeout period. I wonder if there's a straightforward way to account for that, too :thinking_face:
Hm looks correct indeed
Which aleph version are you on btw?
and can you post the full set of request headers? 🙏
aleph version is 0.4.5-alpha3
, a bit old, but this is kinda legacy app I'm maintaining (so that keep-alive-stream
idea was not mine, still thanks though 🙂 )
Then you're missing 061ee43090fcf793942a6b24945af3e7d43b37b1 which might be the fix you're looking for
Try updating to 0.5.0 if possible
Hmm but the PR that includes that commit doesn't seem too relevant: https://github.com/clj-commons/aleph/pull/357 But worth a shot regardless
anyway I'll try to upgrade aleph later in the day or tomorrow and will report tomorrow
The more relevant PR is probably https://github.com/clj-commons/aleph/pull/360, which wasn’t released until 0.4.5-alpha6
Don't think it is - that one affects websockets while @U07M31NA0 is using SSE via the regular HTTP server
Ahh, right, right.
hi guys, I have an update
I've tried to update aleph
to 0.5.0
(had to bump up manifold and netty along the way) but no luck so far - still no Content-Encoding
header
What place in the aleph
source code you would suggest to look into ? Maybe I can come up with the PR to fix this.
Truth to be told it is not my biggest problem right now though, but I might have time later to dig into it.
Thanks! At least we know that we're not chasing an obsolete bug here then 🙂 The deflater is added to the Netty pipeline https://github.com/clj-commons/aleph/blob/master/src/aleph/http/server.clj#L559-L562.
I don't see why it shouldn't work. I also already checked Netty's codebase for whether they have any special handling for text/event-stream
but doesn't seem to be the case.