2015年9月8日火曜日

cURL with HTTP/2


Do you want to check HTTP/2 with cURL command?
Yes. When you compile cURL with nghttp2 from source code, You can do it.

See olso.
HTTP/2 with curl
http://curl.haxx.se/docs/http2.html

Build Environment:
Amazon EC2
CentOS 7 (x86_64) with Updates HVM (ami-89634988)

Install some library
# yum -y groupinstall "Development Tools"
# yum -y install libev libev-devel zlib zlib-devel openssl openssl-devel git
Install nghttp2
# cd /var/tmp
# git clone https://github.com/tatsuhiro-t/nghttp2.git
# cd nghttp2
# autoreconf -i
# automake
# autoconf
# ./configure
# make
# make install
Set library search path
# echo '/usr/local/lib' > /etc/ld.so.conf.d/custom-libs.conf
# ldconfig
# ldconfig -p| grep libnghttp2
 libnghttp2.so.14 (libc6,x86-64) => /usr/local/lib/libnghttp2.so.14
 libnghttp2.so (libc6,x86-64) => /usr/local/lib/libnghttp2.so
Install cURL
# cd /var/tmp
# git clone https://github.com/bagder/curl.git
# cd curl
# ./buildconf
# ./configure --with-nghttp2=/usr/local

Check it.
  HTTP2 support:    enabled (nghttp2)

# make 
# make install
Check cURL Features. Does it have HTTP2?
# ./src/curl -V
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
Check HTTP/2 response with Test URL.
# ./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



Titile pic from Duncan Hull The Internet: Yours For Just £1