Linux命令Curl支持HTTP 2.0 |
您所在的位置:网站首页 › 运动补剂有哪些分别有什么用 › Linux命令Curl支持HTTP 2.0 |
Curl命令不一定支持HTTP 2.0,但某些服务必须需要HTTP2.0,如Apple的推送服务若使用HTTP/1.x协议进行请求,则会返回“Unexpected HTTP/1.x request”的错误。因此就有了让Curl命令支持HTTP/2的实践,其实质就是重新编译Curl命令。 验证curl对HTTP 2.0的支持为了验证默认情况下curl使用的协议,执行命令: [root@host root]# curl -I https://nghttp2.org/ HTTP/1.1 200 OK Date: Tue, 27 Oct 2020 07:53:18 GMT Content-Type: text/html Last-Modified: Tue, 02 Jun 2020 12:23:35 GMT Etag: "5ed644c7-19d8" Accept-Ranges: bytes Content-Length: 6616 X-Backend-Header-Rtt: 0.00096 Strict-Transport-Security: max-age=31536000 Server: nghttpx Via: 2 nghttpx alt-svc: h3-29=":443"; ma=3600 x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block x-content-type-options: nosniff从HTTP/1.1 200 OK可知当前计算机的curl默认使用HTTP 1.1。 HTTP 2.0的启用需要使用--http2开关,看当前curl命令是否支持这个参数,执行命令: [root@host root]# curl --http2 -I https://nghttp2.org/ curl: option --http2: is unknown curl: try 'curl --help' or 'curl --manual' for more information从上面的结果可见,当前计算机的curl不支持HTTP 2.0。 看curl命令支持的特性,从Features里可以看到curl命令是否真的不支持http2: [root@host root]# curl --version curl 7.29.0 (x86_64-koji-linux-gnu) libcurl/7.29.0 NSS/3.28.4 zlib/1.2.7 libidn/1.28 libssh2/1.4.3 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets因为Features里没有HTTP2,因此无法支持HTTP2.0。 增加对HTTP2.0的支持增加对HTTP2.0的支持说白了,就是重新编译一个curl,其中一个重要的依赖是nghttp2。下面就来实际操作一下。注意用root用户的身份安装系统软件。 用yum把当前已安装包升级到最新,并安装依赖的包。 [root@host root]# yum -y update [root@host root]# yum -y install make binutils autoconf automake libtool \ python-setuptools python-devel python3-devel git openssl openssl-devel curl gcc gcc-c++ \ pkgconfig zlib-devel zlib libxml2-devel libev-devel libevent-devel libevdev libevdev-devel \ jansson-devel jemalloc-devel libcurl libicu libmetalink libpsl libssh2 c-ares-devel \ libnghttp2 systemd 安装nghttp2。因为每个命令输出内容较长,这里把命令执行输出部分略去。 [root@host root]# git clone https://github.com/tatsuhiro-t/nghttp2.git [root@host root]# cd nghttp2/ [root@host nghttp2]# autoreconf -i [root@host nghttp2]# automake [root@host nghttp2]# autoconf [root@host nghttp2]# ./configure [root@host nghttp2]# make [root@host nghttp2]# make install [root@host nghttp2]# ldconfig [root@host nghttp2]# cd ..如果上面能正确编译和安装,则可直接到下一步。如果make过程中出现错误:#error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 说明系统的编译器版本过旧,需要进行更多的操作。 [root@host nghttp2]# yum install centos-release-scl [root@host nghttp2]# yum-config-manager --enable rhel-server-rhscl-7-rpms [root@host nghttp2]# yum install devtoolset-7 [root@host nghttp2]# scl enable devtoolset-7 bash上面4个命令执行后,再执行gcc --version就可以看到gcc已经升级到7.0以上。升级完后,继续编译和安装nghttp2。 重新编译curl命令。 [root@host root]# wget https://curl.haxx.se/download/curl-7.73.0.tar.gz [root@host root]# tar -zxvf curl-7.73.0.tar.gz [root@host root]# cd curl-7.73.0/ [root@host curl-7.73.0]# ./configure --with-nghttp2=/usr/local --with-ssl --enable-tls-srp [root@host curl-7.73.0]# make && make install [root@host curl-7.73.0]# ldconfig [root@host curl-7.73.0]# cd ..需要注意,执行configure后,需要确认输出中含有HTTP2: enabled (nghttp2)字样。 确认curl命令已经支持HTTP2.0 [root@host root]# curl --version curl 7.73.0 (x86_64-pc-linux-gnu) libcurl/7.73.0 OpenSSL/1.0.2k-fips zlib/1.2.7 nghttp2/1.42.0-DEV Release-Date: 2020-10-14 Protocols: dict file ftp ftps gopher http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features: AsynchDNS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets这里显示了HTTP2字样,说明curl已经支持了HTTP 2.0。上述操作在CentOS Linux release 7.8系统中验证通过。 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |