Sobes.tech
Middle+

What can you tell us about HTTP/3?

sobes.tech AI

Answer from AI

HTTP/3 is a major version of the HTTP protocol based on QUIC instead of TCP.

Features and advantages:

  • Use of QUIC: Instead of TCP + TLS on top, HTTP/3 works directly over QUIC. QUIC multiplexes streams at the transport protocol level and includes TLS 1.3 for encryption.

  • Elimination of Head-of-Line Blocking (HOLB) at the transport level: Since QUIC multiplexes streams, losing a packet related to one stream does not block the delivery of data for other streams in the same connection. This was an issue in HTTP/2, where adjacent frames from different streams could be blocked due to packet loss at the TCP level.

  • Fast connection establishment: QUIC combines connection setup and TLS handshake, reducing latency.

  • Connection migration: QUIC uses Connection ID, allowing a client connection to remain active when changing IP address or port (e.g., switching between Wi-Fi and cellular networks).

  • Improved packet loss handling: QUIC uses built-in loss detection and recovery mechanisms, which can be more efficient than TCP.

Comparison with HTTP/2:

Feature HTTP/2 (over TCP) HTTP/3 (over QUIC)
Transport TCP + TLS QUIC
HOLB Present at TCP level Not at QUIC level
Connection setup TCP handshake + TLS handshake One RTT (can be 0-RTT on reconnect)
Connection migration No (new TCP connection) Yes (via Connection ID)
Multiplexing Application layer (frames in TCP stream) Transport layer (QUIC streams)

Implementation in Go:

The standard net/http library supports HTTP/3 starting from Go 1.21 experimentally. Full support usually involves external libraries like quic-go, integrated with net/http.

Example usage (client side with quic-go):

// Example of an HTTP/3 client using quic-go
package main

import (
	"crypto/tls"
	"fmt"
	"io"
	"net/http"

	"github.com/quic-go/quic-go/http3" // External library
)

func main() {
	client := &http.Client{
		Transport: &http3.RoundTripper{
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true, // For example only, do not do this in production
			},
		},
	}

	resp, err := client.Get("https://quic.cloud/") // Example server supporting HTTP/3
	if err != nil {
		fmt.Printf("Error fetching URL: %v\n", err)
		return
	}
	defer resp.Body.Close()

	fmt.Printf("HTTP status: %s\n", resp.Status)
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Printf("Error reading response body: %v\n", err)
		return
	}
	fmt.Printf("Response body length: %d\n", len(body))
}