Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Server-Sent Events Utilise HTTP/2 Pipelining

When using SSE through the HTML5 EventSource object, do the requests utilise the HTTP/2 multiplexing / pipelining features? In particular, will SSE requests in different tabs (re)use the same HTTP/2 connection?

I assume so, since SSE is based (AFAIK) on HTTP/1.1 chunked_encoding technology, but wanted to check.

like image 891
acrophobia Avatar asked Sep 01 '16 14:09

acrophobia


2 Answers

Yes they will. Chrome's http2 tag is a great way to explore how http2 requests are emitted: chrome://net-internals/#http2.

For the requests emitted by SSE, you should see something like:

                HTTP2_SESSION_SEND_HEADERS
                        --> exclusive = true
                        --> fin = true
                        --> has_priority = true
                        --> :method: GET
                            :authority: h2.example.org
                            :scheme: https
                            :path: /demo_sse.php
                            accept: text/event-stream
                            cache-control: no-cache
                            referer: https://h2.example.org/
                            accept-encoding: gzip, deflate, sdch, br
                            accept-language: en-US,en;q=0.8,fr;q=0.6,es;q=0.4
                        --> parent_stream_id = 0
                        --> priority = 1
                        --> stream_id = 7

As you can see in this example, the browser sent the request on stream id 7, re-using the connection it had to fetch the html.

like image 138
Frederik Deweerdt Avatar answered Oct 01 '22 11:10

Frederik Deweerdt


Theoretically, yes. And, in practice the answer should be the same, as most browsers have implemented SSE on top of their XmlHttpRequest2 object.

(To be fair, I've not found a definitive reference that says AJAX requests to the same origin are shared across tabs, but it is hard to imagine why a browser would not have allowed that - I've not managed to come up with a security reason, for instance.)

like image 42
Darren Cook Avatar answered Oct 01 '22 11:10

Darren Cook