Linux命令Curl支持HTTP 2.0

您所在的位置:网站首页 运动补剂有哪些分别有什么用 Linux命令Curl支持HTTP 2.0

Linux命令Curl支持HTTP 2.0

2024-07-15 23:16:49| 来源: 网络整理| 查看: 265

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系统中验证通过。



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭