Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requests served from ServiceWorker are downgraded from HTTP/2 to HTTP/1.1

I found a peculiar issue with service workers which apparently downgrades network request served via the worker to HTTP/1.1 even though the HTTP server is serving via HTTP/2. I have found this on all the sites serving on H2 with ServiceWorkers.

I found this on my website and I thought it to be an issue with GatsbyJS. Apparently there is already an issue open which indicates a bug in Chromium.

Is this the expected behavior? Where is this specced?

Here is a link to my site.

like image 249
Ozil Avatar asked Feb 04 '19 10:02

Ozil


People also ask

Why HTTP2 is not widely used?

Due to strict origin rules in the protocol, one HTTP/2 connection cannot control the other across IP addresses and domain names.

How do I know if my site is using HTTP 2?

Google Chrome offers a quick and easy way to check if HTTP/2 is supported on your SSL-enabled site. First, visit your site in Chrome over HTTPS. There you'll see your site listed with protocol h2, confirming your site works over HTTP/2.

How is HTTP version decided?

Each request specifies the HTTP protocol level. The web server decides what to do differently (if anything) based on a request with up/down level versioning. HTTP/1.1 is well established and any decent server will support it.


1 Answers

This is one of the reasons I don't like Service Workers - it messes up the Network tab. Chrome (and Firefox) basically show this as two request:

Double Requests for Service Worker Requests

You see the Web browser requesting the asset from the Service Worker, and then the Service Worker fetching the asset from the Server.

The first request is not shown properly. It shows as HTTP/1.1 and also, when you click on the request, you don't see the HTTP requests headers. Only the second request shows as the full HTTP request (HTTP/2 and with full request and response headers). If you look at your server logs, or if you delete your service worker and look at the Disk Cache load in the Network tab, it will show as HTTP/2.

Does this matter? Well arguably not. The Service Worker is part of the browser and while I don't know the exact detail of how this works at a low level (and can't find where this is specced), the browser probably isn't really talking HTTP between browser and ServiceWorker. In fact if it is, then it's not doing it right as the the HTTP request is for the server domain so has been directed to the wrong place (to be real HTTP it should probably point to localhost and a port number that the service worker is running under)! So should it show something else other than HTTP/1.1? Or show the ultimate network protocol used (h2 in this case)? Maybe.

And when you are dealing with local servers/services the difference between HTTP/1.1 and HTTP/2 are negligible. HTTP/2 comes into it's own over high latency, low bandwidth connections (client to server) and not for local requests. And as I stated the ServiceWorker to server connection is requested over HTTP/2.

In many ways is the same as when the HTTP cache is used (either Disk Cache or Memory Cache), the browser never shows the original HTTP request headers - it just shows: "Provisional headers are shown". Again it probably would be more helpful to show the headers requested (either those requested for that request, or the headers that were used for the original request that was cached).

like image 179
Barry Pollard Avatar answered Nov 24 '22 00:11

Barry Pollard