老师您好!请问该怎么理解这个“可见性”的意思?
您在视频中说提到了 HTTP/1.1因为是用ASCII编码,对头部和内容都可以很容易的修改。那HTTP/2是用的二进制编码,可见性不那么好。不管是从chrom面板中还是wireshark都可以很清晰的看见请求头部字段。
我还从Chrome面板中复制了h2的curl请求(不知道这样合不合理)去通过终端请求,结果得到结果如下:
[root@localhost ~]# curl 'https://http2.akamai.com/demo/h2_demo_frame.html' -H 'authority: http2.akamai.com' -H 'pragma: no-cache' -H 'cache-control: no-cache' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36' -H 'sec-fetch-mode: nested-navigate' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'sec-fetch-site: same-origin' -H 'referer: https://http2.akamai.com/demo' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: zh-CN,zh;q=0.9' --compressed -I
HTTP/1.1 200 OK
Server: Apache
ETag: "a36c5bf5b522a6a2bd2842c9cafb76d8:1441001436"
Last-Modified: Mon, 31 Aug 2015 06:09:25 GMT
Accept-Ranges: bytes
Content-Length: 39079
push: true
rtt: 127
ghost_ip: 104.71.159.169
ghost_service_ip: 23.3.104.110
client_real_ip: 112.94.43.29
client_ip: 112.94.43.29
myproto:
protocol_negotiation: h1
Expires: Thu, 17 Oct 2019 01:51:57 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Thu, 17 Oct 2019 01:51:57 GMT
Connection: keep-alive
Content-Type: text/html;charset=UTF-8
Accept-CH: DPR, Width, Viewport-Width, Downlink, Save-Data
Access-Control-Max-Age: 86400
Access-Control-Allow-Credentials: false
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: GET,HEAD,POST
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
为啥响应还是HTTP/1.1 ?
展开
作者回复: 1、这是因为chrome或者wireshark把二进制报文解析出后,以友好的字符串形式向你展示。在你用chrome时,是看不到Frame细节的,例如weight权重。
2、你访问的网站既支持http1也支持http2。如果想使curl使用http2,需要加入参数--http2。当然,首先你的curl版本要支持。可参考这篇文章:https://www.sysgeek.cn/curl-with-http2-support/