从ServiceWorker服务的请求从HTTP/2降级为HTTP/1.1 [英] Requests served from ServiceWorker are downgraded from HTTP/2 to HTTP/1.1

查看:262
本文介绍了从ServiceWorker服务的请求从HTTP/2降级为HTTP/1.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现服务工作者存在一个特殊的问题,即使HTTP服务器通过HTTP/2进行服务,它也显然将通过该工作者提供的网络请求降级为HTTP/1.1.我在ServiceWorkers在H2上服务的所有站点上都发现了这一点.

我在我的网站上找到了这个,我认为这是GatsbyJS的问题. 显然,有问题已经打开,表明Chromium中存在错误.

这是预期的行为吗?这种地方在哪里?

这是链接到我的网站.

解决方案

这是我不喜欢服务人员的原因之一-将网络"标签弄乱了. Chrome(和Firefox)基本上将其显示为两个请求:

您看到Web浏览器从Service Worker请求资产,然后Service Worker从服务器获取资产.

第一个请求未正确显示.它显示为HTTP/1.1,并且,当您单击请求时,您不会看到HTTP请求标头.仅第二个请求显示为完整的HTTP请求(HTTP/2以及完整的请求和响应标头).如果您查看服务器日志,或者删除服务工作者并查看网络"选项卡中的磁盘缓存"负载,它将显示为HTTP/2.

这有关系吗?可以说不是. Service Worker是浏览器的一部分,虽然我不知道它在低层如何工作的确切细节(并且找不到该位置),但浏览器可能并没有真正在浏览器和浏览器之间使用HTTP. ServiceWorker.实际上,如果它是正确的,那么它就做错了,因为HTTP请求是针对服务器域的,因此已被定向到错误的位置(要成为真实的HTTP,它可能应该指向localhost和服务工作者所使用的端口号下运行)!那么它应该显示除HTTP/1.1之外的其他内容吗?还是显示最终使用的网络协议(在这种情况下为h2)?也许.

在处理本地服务器/服务时,HTTP/1.1和HTTP/2之间的差异可以忽略不计. HTTP/2通过高延迟,低带宽连接(客户端到服务器)而不是本地请求进入自身.正如我所说的,ServiceWorker与服务器的连接是通过HTTP/2请求的.

在许多方面与使用HTTP高速缓存(磁盘高速缓存或内存高速缓存)时相同,浏览器从不显示原始的HTTP请求标头-它仅显示:显示了临时标头".同样,显示请求的标头(该请求的标头或用于缓存的原始请求的标头)可能会更有用.

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.

解决方案

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:

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

这篇关于从ServiceWorker服务的请求从HTTP/2降级为HTTP/1.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆