在Mac OS X上使用 curl 测试http2

发表于 2017-11-08   |   分类于 随笔

curl 是平常工作做经常使用到的工具,但是 curl 默认走 HTTP/1.1 协议。如何在 mac 上支持 HTTP/2,下面是我的一个经历。网上找到参考:Blog — Simone Carletti

1. 查看 curl 的功能特性没有支持 HTTP/2

curl --version or brew info curl 

或者可以直接验证测试是不是支持,下面表示不支持:

curl -I https://www.upyun.com/ --http2 
curl: (1) Unsupported protocol

2. Mac 上安装 HTTP/2 模块

建议使用 [Homebrew][2] 来重新安装 curl 通过 --with-nghttp2 来添加 HTTP/2 支持以及必要的依赖关系。
brew install curl --with-nghttp2

可能会遇到这个错误提示:

 curl
cannot be installed as a binary package and must be built from source.
Install the Command Line Tools:
  xcode-select --install

可以更具提示安装一下 xcode-select --install 然后在重新安装一下 brew install curl --with-nghttp2

3. 强制链接一下

brew link curl --force

4.关闭 shell 窗口,重新打开,就可以愉快的通过 curl 测试 HTTP/2

curl -I https://www.upyun.com/ --http2
HTTP/2 200
server: upyun/0.2
date: Wed, 08 Nov 2017 09:54:44 GMT
content-type: text/html; charset=UTF-8
content-length: 317264
vary: Accept-Encoding
x-dns-prefetch-control: off
x-download-options: noopen
accept-ranges: bytes
cache-control: public, max-age=604800
last-modified: Wed, 08 Nov 2017 07:58:22 GMT
etag: W/"4d750-15f9aa31d30"
strict-transport-security: max-age=63072000
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
所有用户赞赏通道:

仅有 1 条评论


  1. 阿强

    666

    阿强 May 19th, 2020 at 02:30 pm回复

发表新评论

© ICP: 浙ICP备17033011号-1