Does Server-Sent Events Utilise HTTP/2 Pipelining
Asked Answered
C

2

7

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.

Conventioneer answered 1/9, 2016 at 14:53 Comment(1)
HTTP/2 works on the transport level and it's more close to TLS (to be exact it's implemented mostly as application-layer protocol negotiation (ALPN) extension to TLS) as the replacement to HTTP 1.1. Thus Server-Sent Events have no problems in combination with HTTP/2 and should utilize pipelining features. One of the design goal of HTTP/2 was: old applications, which been developed to use HTTP 1.1, should use the most advantages of HTTP/2 automatically (one still have to make modifications to use Server Push).Chickaree
E
3

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.

Eppie answered 3/9, 2016 at 4:1 Comment(0)
H
1

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

Handicraft answered 2/9, 2016 at 12:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.