Skip to content

Instantly share code, notes, and snippets.

@9seconds
Created February 26, 2018 14:07
Show Gist options
  • Save 9seconds/e84285e6e269dec06df988c1ca158b82 to your computer and use it in GitHub Desktop.
Save 9seconds/e84285e6e269dec06df988c1ca158b82 to your computer and use it in GitHub Desktop.
pycurl http2
import io
import pycurl
curl = pycurl.Curl()
curl.setopt(curl.URL, "https://nghttp2.org")
curl.setopt(pycurl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_2_0)
curl.setopt(pycurl.VERBOSE, 1)
with io.BytesIO() as buf:
curl.setopt(curl.WRITEFUNCTION, buf.write)
curl.perform()
➜ python3 curl.py
* Rebuilt URL to: https://nghttp2.org/
* Trying 139.162.123.134...
* Trying 2400:8902::f03c:91ff:fe69:a454...
* Immediate connect fail for 2400:8902::f03c:91ff:fe69:a454: Network is unreachable
* Connected to nghttp2.org (139.162.123.134) port 443 (#0)
* found 149 certificates in /etc/ssl/certs/ca-certificates.crt
* found 596 certificates in /etc/ssl/certs
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_ECDSA_AES_256_GCM_SHA384
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: nghttp2.org (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: EC
* certificate version: #3
* subject: CN=nghttp2.org
* start date: Tue, 20 Feb 2018 00:00:08 GMT
* expire date: Mon, 21 May 2018 00:00:08 GMT
* issuer: C=US,O=Let's Encrypt,CN=Let's Encrypt Authority X3
* compression: NULL
* ALPN, server accepted to use h2
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* TCP_NODELAY set
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x1c106b0)
> GET / HTTP/1.1
Host: nghttp2.org
User-Agent: PycURL/7.43.0 libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 nghttp2/1.7.1 librtmp/2.3
Accept: */*
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2.0 200
< date:Mon, 26 Feb 2018 14:05:48 GMT
< content-type:text/html
< last-modified:Fri, 02 Feb 2018 12:39:22 GMT
< etag:"5a745bfa-19d8"
< accept-ranges:bytes
< content-length:6616
< x-backend-header-rtt:0.001619
< strict-transport-security:max-age=31536000
< server:nghttpx
< via:2 nghttpx
< x-frame-options:SAMEORIGIN
< x-xss-protection:1; mode=block
< x-content-type-options:nosniff
<
* Connection #0 to host nghttp2.org left intact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment