AndyJRR AndyJRR - 2 years ago 182
Javascript Question

SSE over https not working

I am having an issue with SSE over https, let me make it clear, I have an Nginx server that listen to https, and a Rails Puma in the back, So I have this in the js( coffescript ):

initStream = () ->
rechargePayment.source = new

and in the rails controller I have:

def stream
response.headers['Content-Type'] = 'text/event-stream'
redis =
redis.psubscribe(['proggress.refresh', 'heartbeat']) do |on|
on.pmessage do |_pattern, event, data|"event: #{event}\n")"data: #{data}\n\n")
rescue IOError 'Stream stoped'
ensure 'Stopping Stream Thread'

When I try this over https, it does nothing, in the logs I only see the error: "Stream closed", but if I try it over http it works perfectly.

EDIT: I saw this:
"The EventSource interface is used to receive server-sent events. It connects to a server over HTTP and receives events in text/event-stream format without closing the connection."


So, does this mean that it works only in http?

Answer Source

So yeah, the issue was in the nginx, I had to put these settings:

proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;

and in the rails controller add this:

response.headers['X-Accel-Buffering'] = 'no'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download