Search code examples
htmlvarnishserver-sent-events

Server-sent events through a varnish proxy


I have a website running behind a Varnish proxy. Any connection open for server-sent events never gets any content and never closes. Varnish seems to wait for the content stream to end before forwarding that content to the browser. And it keeps the connection open to the server until the content ends. Both of those issues are incompatible with server-sent events.

How can I configure Varnish to flush content immediately to the browser and close its connection to the server when the browser closes its connection?

Or can I dynamically instruct Varnish to act entirely as a pass-through for connections as if it weren't even there? I can run the exact same web application on non-proxied systems with no problems. And I can't completely bypass Varnish in this setup (e.g. different port).


Solution

  • Have you tried to return pipe in vcl_recv ?

    From the documentation :

    Pipe can be returned from vcl_recv as well. Pipe short circuits the client and the backend connections and Varnish will just sit there and shuffle bytes back and forth. Varnish will not look at the data being send back and forth - so your logs will be incomplete. Beware that with HTTP 1.1 a client can send several requests on the same connection and so you should instruct Varnish to add a "Connection: close" header before actually returning pipe.

    Don't miss that you have to return pipe only for SSE incoming requests.