- How do I install curl with http2 support. Ask Question Asked 4 years, 2 months ago. Active 2 years, 3 months ago. Viewed 22k times 18. It seems like curl packed.
- It will even default to using HTTP/2 when given a HTTPS URL since doing so implies no penalty and when curl is used with sites that do not support HTTP/2 the request will instead negotiate HTTP/1.1.
Protocol dependencies
TCP: Typically, HTTP/2 uses TCP as its transport protocol. The well known TCP port for HTTP/2 traffic is 443 (and 80).
Edit: The standard library won’t include the H2C handler, it will remain in the x/net/http2/h2c package. In go, the standard http.Client is used for HTTP/2 requests as well. The only difference is the usage of http2.Transport instead of http.Transport in the client’s Transport field. Nghttp2: HTTP/2 C Library. Feb 16 th, 2015 11:16 pm. Nghttp2 is an implementation of HTTP/2 and its header compression algorithm HPACK in C. The framing layer of HTTP/2 is implemented as a form of reusable C library.
Wireshark
ChangeLog:
- Wireshark 1.12 - initial support
- Wireshark 2.0 - initial HPACK support (header decompression)
- Wireshark 2.4 - header decompression support now requires external nghttp2 package (true for official Windows/macOS builds).
Example capture file
http2-h2c.pcap - HTTP/2 via Upgrade: h2 mechanism (curl --http2 -v nghttp2.org/robots.txt nghttp2.org/humans.txt)
Sample of HTTP2 (draft-14) - Created with nghttp2, need to use Decode as HTTP2
On the SampleCaptures page, there is also http2-16-ssl.pcapng containing a HTTP2 (draft 16) over SSL capture (with keys) and a link to a TLS 1.3 HTTP/2 capture.
Display Filter
A complete list of HTTP2 display filter fields can be found in the display filter reference
Show only the HTTP2 based traffic: http2
Capture Filter
You cannot directly filter HTTP2 protocols while capturing. However, if you know the TCP port used (see above), you can filter on that one.
Capture only the HTTP2 traffic over the default port (443):
External links
RFC 7540Hypertext Transfer Protocol version 2
RFC 7541HPACK - Header Compression for HTTP/2
HTTP/2 ImplementationsOfficial page with all HTTP2 Implementations
Discussion
See why HTTP/2 might be for you!
Join the DZone community and get the full member experience.
Join For FreeThe web is built on small HTTP exchanges. HTTP runs on TCP, which is aimed at long running transfers — it is not cut out for small exchanges that are common with HTTP. There is a lot of overhead caused by TCP in a modern website where only a fraction of time is spent downloading content. HTTP/2 addresses these performance problems. In this article, we will review how HTTP/2 works under the hood and introduce tools to get started with HTTP/2.
You may also like: TLS/SSL Explained: TLS/SSL Terminology and Basics.
TCP
The Internet consists of five layers of TCP/IP. All applications run on the Transport layer, which, for HTTP, is TCP.
The first thing that takes place when establishing a TCP connection is what is known as Three-Way handshake.
Every time a new HTTP request is made, the TCP Three-Way handshake adds this overhead before HTTP Request can be made. Every TCP connection is then closed with a Three-Way handshake too. This adds latency in order of tens of milliseconds for every HTTP request. The HTTP Header Connection: Keep-Alive
introduced in HTTP/1.1 solves this problem to some extent.
TCP is a reliable protocol — every packet sent by the client is acknowledged. This relieves applications from the complex problems of loosing packets or receiving them out-of-order. This, however, introduces another problem — Head-of-line blocking in addition to increasing the overhead.
TCP deals with network congestion using flow control. TCP slow start is a flow control mechanism where it gradually increases the TCP window size until it finds the network's maximum carrying capacity. The TCP slow start adds to the latency in HTTP requests and responses.
HTTP/2
HTTP/2 addresses the shortcomings of TCP. It is a binary protocol that keeps the same semantics as HTTP 1.x, meaning that all the headers, verbs, resources, etc. work in the same way. It is more about solving issues with TCP than fixing problems with HTTP 1.x.
HTTP/2 Connection
There are two ways to make an HTTP/2 connection
Establishing an h2c connection. HTTP/2 can work over HTTP connection over plain text.
Establishing an h2c connection Establishing an h2 connection. Predominant way of using HTTP/2 is to establish connection over HTTPS.
Establishing h2c connection
Frames constitute the basic protocol unit in HTTP/2 and are used to communicate data — request, reponse, header, or body.
The header frames are compressed using HPACK.
Streams
Streams represent a logical single request/response communication. A stream is just a bidirectional sequence of frames that share a common identifier. This enables interleaving of frames from multiple streams together that allows for multiplexed communication over a single connection.
HTTP/2 uses single TCP connection per host. It provides bi-directional multiplexing via streams allowing for concurrent requests and responses. Streams can be prioritized as well as subjected to flow control.
Server Push
Server push is a function available in HTTP/2 whereby a server can push resources to the client without having client request them. It still provides clients with control whether it wants to accept the data or not. Although, server push eliminates the need to inline resources, e.g., JavaScript, CSS, it does not replace other technologies, e.g., WebSockets.
Tools
We will use tools that support HTTP/2 to investigate HTTP/2 connections.
1. cURL. HTTP/2 support was added in version 7.33+. It uses nghttp2 library under the covers. The command line parameter --http2
can be used to make HTTP/2 requests, e.g., curl --http2 domain.com
. Alternatively, a Docker image can be used for cURL that supports HTTP/2.
2. Chrome Tools. Chrome provides protocol information under the Network tab.
Chrome also provides chrome://net-export
to save netlogs that can be used to view HTTP/2 sessions using external netlog viewer — https://netlog-viewer.appspot.com.
3. Wireshark. Wireshark can be used to view HTTP/2 exchanges, as it supports decrypting of SSL. To do so, we need to export the environment variable SSHKEYLOGFILE from the browser and configure Wireshark to use this sslkeylog file.
HTTP/2 in Action
We will use tools to do exercises that will help us understand HTTP/2 better.
1. HTTP/2 demo. Let us start by checking if our browser supports HTTP/2. Open the Akamai website in your Chrome browser. Check out the demo that shows how HTTP/2 improves performance and load time.
2. HTTP/2 Connection. Use cURL to connect to an HTTP/2 server serving plain text. The client first connects to the server over HTTP/1.1 and sends an upgrade request. The server responds with 101 Switching Protocols
, and then the connection upgrades to HTTP/2.
Next, let's connect to an HTTP/2 server over TLS. To decrypt TLS traffic in Wireshark, set the environment variable
or, launch Chrome Canary with flag --ssl-key-log-file
.
To launch Wireshark, go to Edit->Preferences->Protocols. Select TLS, and set the logfile name to the same file as set in the environment variable SSHKEYLOGFILE. With this set, we'll be able to decrypt TLS traffic. Start traffic capture in Wireshark, and in your Chrome browser, open https://http2.golang.org/.
3. HTTP/2 Stream Exchange. Go to https://http2.golang.org/gophertiles in Chrome browser and see the HTTP/2 Streams in Wireshark. You can also use Chrome Developer Tools to see the HTTP/2 exchanges under Network tab.
4. HTTP/2 Priorities. nghttp2 not only provides a library that cURL uses, but it also provides an HTTP/2 server that implements HTTP/2 priorities based on content-type — it first serves HTML, followed by CSS, and then JavaScript. It is available as a Docker image.
The nghttp client can be used to connect to an HTTP/2 server.
We'll create a simple application consisting of HTML, CSS and JavaScript and will have nghttpd server, which is a HTTP/2 server, serve it over TLS. Create folders — certs
and docs
. The certs
folder will store private key and certificate; docs
will store the application.
Generate a self-signed certificate.
Create the application.
Now launch nghttpd.
Open the browser and hit https://127.0.0.1/index.html. Usechrome://net-export
to save netlogs and then view the netlog file using netlog viewer — https://netlog-viewer.appspot.com. We can see that HTML is served first, followed by CSS, and then JavaScript — the priority determined by the nghttpd server.
5. Server Push. We can configure server to push a resource when it gets request for another resource. Let us push CSS file when we get request for HTML.
Start nghttpd server with -p
option to indicate that it should push style.css
when a request is made for index.html
file. Export the netlog file and view using netlog viewer to see the session showing PUSH details.
6. Working with HTTP/2 Library. Java library okhttp can be used to connect to an HTTP/2 server. Code illustrating HTTP/2 Request using okhttp can be downloaded from my GitHub. Remember to pass-Xbootclasspath/p:alpn-boot-8.1.13.v20181017.jar
as VM Option in IntelliJ Run Configuration if you are using Java version 8. Java 9 and above has native ALPN support and this VM option is not supported.
Conclusion
In this article, we looked at how HTTP/2 addresses some of the performance issues seen in modern web applications. We introduced few tools to get up to speed with HTTP/2. There are many resources on the web to learn more.
Further Reading
Curl Http2 Windows
- The Purpose of SSL Certificates and Why They Are Important.
- HTTP Methods [Video].
Curl Http2 Windows
Opinions expressed by DZone contributors are their own.