Build cURL with HTTP/2
  • 4,619 views,
  • 2017-10-20,
  • 上傳者: Kuann Hung,
  •  0
如果實在需要用 cURL,也要支援 HTT/2 的話,可以使用 nghttp2
編譯方式如下:
 
步驟
1.
安裝編譯環境
yum -y groupinstall "Development Tools"
yum -y install libev libev-devel zlib zlib-devel openssl openssl-devel git
2.
安裝 nghttp2
cd /var/tmp
git clone https://github.com/tatsuhiro-t/nghttp2.git
cd nghttp2
autoreconf -i
automake
autoconf
./configure
make
make install
 
3.
設定 Lib 搜尋路徑
echo '/usr/local/lib' > /etc/ld.so.conf.d/custom-libs.conf
ldconfig
ldconfig -p | grep libnghttp2
4.
安裝 cURL
cd /var/tmp
git clone https://github.com/bagder/curl.git
cd curl
./buildconf
./configure --with-nghttp2=/usr/local

make
make install
重新設定路徑
echo '/usr/local/lib' > /etc/ld.so.conf.d/custom-libs.conf
ldconfig
ldconfig -p | grep libnghttp2
5.
測試 cURL HTTP/2 
./src/curl -V
 
看輸出是否有 HTTP2 的字眼
curl 7.45.0-DEV (x86_64-unknown-linux-gnu) libcurl/7.45.0-DEV OpenSSL/1.0.1e zlib/1.2.7 nghttp2/1.3.1-DEV
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz HTTP2 UnixSockets
6.
利用 http2bin 測試
./src/curl --http2 -v https://http2bin.org/get
 
輸出參考如下:
*   Trying 104.131.161.90...
* Connected to http2bin.org (104.131.161.90) port 443 (#0)
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* NPN, negotiated HTTP2 (h2)
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Unknown (67):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*   subject: OU=Domain Control Validated; OU=EssentialSSL; CN=www.http2bin.org
*   start date: 2015-02-21 00:00:00 GMT
*   expire date: 2016-02-21 23:59:59 GMT
*   subjectAltName: http2bin.org matched
*   issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
*   SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x1c59450)
> GET /get HTTP/1.1
> Host: http2bin.org
> User-Agent: curl/7.45.0-DEV
> Accept: */*
>
* http2_recv: 16384 bytes buffer at 0x1c59d60 (stream 1)
* http2_recv: 16384 bytes buffer at 0x1c59d60 (stream 1)
* http2_recv: 16384 bytes buffer at 0x1c59d60 (stream 1)
* http2_recv: returns 466 for stream 1
< HTTP/2.0 200
< server:h2o/1.2.0
< date:Tue, 08 Sep 2015 03:41:11 GMT
< content-type:application/json
< access-control-allow-origin:*
< access-control-allow-credentials:true
< x-clacks-overhead:GNU Terry Pratchett
<
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Connection": "keep-alive",
    "Host": "http2bin.org",
    "User-Agent": "curl/7.45.0-DEV",
    "Via": "2 http2bin.org"
  },
  "origin": "54.65.241.177",
  "url": "https://http2bin.org/get"
}
* Connection #0 to host http2bin.org left intact
Facebook 討論區載入中...
資料夾 :
標籤 :
發表時間 :
2017-10-20 22:53:19
觀看數 :
4,619
發表人 :
Kuann Hung
部門 :
老洪的 IT 學習系統
QR Code :