前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >curl 支持 HTTP2

curl 支持 HTTP2

作者头像
py3study
发布2020-01-06 18:28:58
4.1K0
发布2020-01-06 18:28:58
举报
文章被收录于专栏:python3python3

curl 命令支持 HTTP2

执行以下命令:

代码语言:javascript
复制
sudo apt-get install -y tmux curl vim wget htop git

首先使用 curl 请求 https://nghttp2.org(使用了 http2)。但是结果却是返回了 HTTP1.1 响应:

代码语言:javascript
复制
$ curl -I https://nghttp2.org/

HTTP/1.1 200 OK
Date: Fri, 04 Dec 2015 00:00:06 GMT
Content-Type: text/html
Content-Length: 6680
Last-Modified: Thu, 26 Nov 2015 15:28:33 GMT
Etag: "56572521-1a18"
Accept-Ranges: bytes
X-Backend-Header-Rtt: 0.000642
Server: nghttpx nghttp2/1.5.1-DEV
Via: 1.1 nghttpx
strict-transport-security: max-age=31536000

如果使用 http2,会给我们返回一个协议不支持的错误。

代码语言:javascript
复制
$ curl --http2 -I https://nghttp2.org/
# Unsupported protocol error

安装 nghttp2

安装 nghttp2 ad 工具(http2 的 C 库支持):

代码语言:javascript
复制
# Get build requirements
# Some of these are used for the Python bindings
# this package also installs
sudo apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config \
  zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev libjansson-dev \
  libjemalloc-dev cython python3-dev python-setuptools

# Build nghttp2 from source
git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2
autoreconf -i
automake
autoconf
./configure
make
sudo make install

更新到最新的 curl 版本:

代码语言:javascript
复制
cd ~
sudo apt-get build-dep curl
wget http://curl.haxx.se/download/curl-7.46.0.tar.bz2
tar -xvjf curl-7.46.0.tar.bz2
cd curl-7.46.0
./configure --with-nghttp2=/usr/local --with-ssl
make
sudo make install
sudo ldconfig

通过 ldconfig 命令使得 curl 命令可以正常工作,但是你也可以尝试如下命令:

代码语言:javascript
复制
# Try this out first
curl --http2 -I nghttp2.org

# If you get errors, try setting this constant
# to tell curl where to find shared libraries
LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/curl --http2 -I nghttp2.org

测试 curl

代码语言:javascript
复制
LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/curl --http2 -k -I -H "Host: example.com" https://localhost
> HTTP/2.0 200
> server:nginx/1.9.7
> date:Fri, 04 Dec 2015 02:20:54 GMT
> content-type:text/html
> content-length:12
> last-modified:Fri, 04 Dec 2015 02:11:11 GMT
> etag:"5660f63f-c"
> accept-ranges:bytes

参考资源

原文:https://serversforhackers.com/video/curl-with-http2-support?utm_campaign=Servers%2Bfor%2BHackers&utm_medium=email&utm_source=Servers_for_Hackers_1

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-10-08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装 nghttp2
  • 测试 curl
  • 参考资源
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档