简体   繁体   中英

Event Source (Server Sent Events) over http2 through Microsoft Azure web app

I've set up a web app on Microsoft Azure for a NodeJS server that handles Server Sent Events. And I have also set up a static web application as a client. Both seem to be working fine and the client can send an event source request to the server and the server receives it and starts to process. But the client never receives a response and the event source stays "Pending" and eventually times out.

This is the function that the server does enter to send out a request:

response.writeHead(200, {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Access-Control-Allow-Origin': "*",
    'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
});

response.write('id: ' + id + '\n');
if (event) {
    response.write('event: ' + event + '\n');
}
response.write("data: " + data + '\n\n');

Locally it works perfectly fine over HTTP2. Anyone knows if there is a setting I'm missing?

In my case it was buffering issue. I did not get a response or got with huge delay.

I have added headers to disable cache and buffering for the response.

X-Accel-Buffering: no;

It helped me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM