Search code examples
server-sent-eventshttp2http-1.1

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.


Solution

  • 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.