-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to proxy Server Sent Events? #677
Comments
I'm wondering the same for a Python Odoo module and Chrome App integration. If helps in Nginx I solve it with this directives in the location:
Maybe the websocket presets in the proxy directive it's doing the same?? |
In order to support server sent events going through an See example here. |
@shurcooL Ha! I remember when you showed me that code when you first wrote it. I was actually looking at that struct field but wasn't quite sure if it was the culprit, and I haven't had the time to investigate it right now. Would somebody please try it in Caddy for server-sent events? Here is the value to set: https://github.com/mholt/caddy/blob/f1ba7fa34353682b15a2e15d10b15413d60a6c12/middleware/proxy/reverseproxy.go#L47 - try |
It surprises me that your Nginx configuration turns chunked-encoding off @aek, because I'd expect it to be necessary (or at least preferential) for SSE. If you'd want this to work in Caddy, I think you'd need to convince it to flush data as soon as it comes in from the destination connection. I think the parts of the above Nginx config that make it work there are As far as I can tell, the FlushInterval [1] in middleware/proxy is never set, so the proxy directive might need this as a new parameter to make this work. |
ha, didn't refresh this page in a while, it seems I'm late to the party... |
I think you could set it here, just to make sure setting the value fixes it: https://github.com/mholt/caddy/blob/f4c729bd2205b939f93fad068bbbd7161802f695/middleware/proxy/reverseproxy.go#L102 |
Aye, that should do it! ^ If somebody who has a SSE backend would like to set that value and report how it goes, that would be fantastic. If that works, then we can make plans to implement a fix in Caddy. |
I tried to add a 1 second flush interval with |
@larskluge Are you sure you were running the modified binary? Use the build script |
I built w/
|
Interesting; is there any more details about the upstream you can give us to reproduce the issue? Maybe compare to @shurcooL's setup... |
Perhaps try my config,
This is a temp deploy, the address won't work for too long. Anyway, compare calling it directly:
vs. running the above config locally:
|
@larskluge Thanks for the details. I was able to see the same behavior. The culprit is this line -- in other words, dst is not a writeFlusher type. Notice that if you remove the It's really late here, so I'm gonna sleep on it; somebody is welcome to fix this before I get around to it if they want to. 😄 |
K, nevermind, I just took care of it... why let it linger. @larskluge and @kidwm and @aek please try the latest changes and let me know how it goes! |
Awesome, works perfectly well—thank you @mholt !! |
I've run into the same issue using the latest version of Caddy (0.9.3). I try to run a YouTrack 7.0 install behind Caddy and it seems SSE doesn't work. I tried to play with FlushInterval but with no luck so far. I'm not really familiar with Go and the internals of Caddy, so I put a few
YouTrack has an official proxy guide for e.g. Nginx where they recommend to use the following options:
If you can point me in any directions I would be more than happy to help as well. |
@mholt May I open a new issue for this or it would be more practical to reopen this one? |
You can open a new issue, thanks. :) |
I used a nodejs backend to offer event source, but failed to access it through Caddy proxy.
Is it possible to do this way in Caddy server?
The text was updated successfully, but these errors were encountered: