tpeczek/Lib.AspNetCore.ServerSentEvents

HTTP headers required for reverse-proxy configurations

dviry opened this issue · 2 comments

dviry commented

Running my ASP.NET Core app with SSE behind nginx configured as a reverse-proxy, and the sse connection throws many "net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)" errors.

According to this answer it would be enough to appropriately set some headers on response; yet I found no way for me to customize those (except adding an additional middleware before it to set those headers). Would you consider setting those HTTP headers always, or at least provide an extension point (in the ServerSentEventsServiceOptions.cs) to allow configuring those?

Thanks in advance

I would prefer to add an extension point, my intial thought goes in direction of something similar to what static files middleware provides:

public class Startup
{
    ...

    public void Configure(IApplicationBuilder app)
    {
        ...

        app.MapServerSentEvents("/default-sse-endpoint", new ServerSentEventsOptions
        {
            OnPrepareAccept = response =>
            {
                response.Headers.Append("Cache-Control", "no-cache");
                response.Headers.Append("X-Accel-Buffering", "no");
            }
        });

        ...
    }
}

I'm assuming this would solve your case?

dviry commented