Go QUIC 服务示例
本页目录 3
后端
git clone --depth 1 https://github.com/sunmery/quic-gin-example.gitcd quic-gin-examplego mod tidygo run server.go新开一个 终端运行客户端
go run client.go使用 QUIC+HTTP3 的 curl来查看详细的网络请求和测试:
查看当前 curl 版本:
curl --version输出包含HTTP3则代表该 curl支持
curl 8.13.0-DEV (aarch64-apple-darwin24.3.0) libcurl/8.13.0-DEV quictls/3.1.4 zlib/1.2.12 libidn2/2.3.7 libpsl/0.21.5 ngtcp2/1.12.0-DEV nghttp3/1.9Release-Date: [unreleased]Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wssFeatures: alt-svc AsynchDNS HSTS HTTP3 HTTPS-proxy IDN IPv6 Largefile libz NTLM PSL SSL threadsafe TLS-SRP UnixSockets测试服务
- 仅 HTTP3
curl --http3-only -kv https://localhost:443正确则输出:
* Host localhost:443 was resolved.* IPv6: ::1* IPv4: 127.0.0.1* Trying [::1]:443...* Server certificate:* subject: CN=localhost* start date: Mar 17 23:51:13 2025 GMT* expire date: Mar 17 23:51:13 2026 GMT* issuer: CN=localhost* SSL certificate verify result: self-signed certificate (18), continuing anyway.* Certificate level 0: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption* Connected to localhost (::1) port 443* using HTTP/3* [HTTP/3] [0] OPENED stream for https://localhost:443/* [HTTP/3] [0] [:method: GET]* [HTTP/3] [0] [:scheme: https]* [HTTP/3] [0] [:authority: localhost]* [HTTP/3] [0] [:path: /]* [HTTP/3] [0] [user-agent: curl/8.13.0-DEV]* [HTTP/3] [0] [accept: */*]> GET / HTTP/3> Host: localhost> User-Agent: curl/8.13.0-DEV> Accept: */*>* Request completely sent off< HTTP/3 200< content-type: application/json; charset=utf-8< date: Tue, 18 Mar 2025 01:49:40 GMT< content-length: 32<* Connection #0 to host localhost left intact{"message":"Hello over HTTP/3!"}- 测试:
curl --http3 https://localhost:443 \ --resolve https://localhost:443:127.0.0.1 \ -kIv预期:
* SSL connection using TLSv1.3* ALPN: server accepted h3* HTTP/3 200网站测试:
https://http3.wcode.net查看支持 HTTP3 的网站, 例如h2o.examp1e.net
https://http3.wcode.net/?q=h2o.examp1e.net浏览器
火狐 QUIC 设置
https://sites.google.com/view/a-bit-better-privacy/http3-hypertext-transfer-protocol
curl
编译
第 4 步可以禁用 libpsl:大多数场景下,libpsl 是可选的依赖,禁用后不影响 HTTP/3 的核心功能:
./configure \ LDFLAGS="-Wl,-rpath,$HOME/quictls/lib" \ --with-openssl=$HOME/quictls \ --with-nghttp3=$HOME/nghttp3 \ --with-ngtcp2=$HOME/ngtcp2#### 0. 安装依赖brew install autoconf automake libtool pkg-config cmake libpsl
#### 1. 编译 quictls(OpenSSL 的 QUIC 分支)git clone --depth 1 -b openssl-3.1.4+quic https://github.com/quictls/opensslcd openssl./config enable-tls1_3 --prefix=$HOME/quictlsmake -j$(sysctl -n hw.logicalcpu)make installcd ..
#### 2. 编译 nghttp3git clone https://github.com/ngtcp2/nghttp3cd nghttp3autoreconf -fi./configure --prefix=$HOME/nghttp3 --enable-lib-onlymake -j$(sysctl -n hw.logicalcpu)make installcd ..
#### 3. 编译 ngtcp2git clone https://github.com/ngtcp2/ngtcp2 --recurse-submodulescd ngtcp2autoreconf -fi./configure PKG_CONFIG_PATH=$HOME/quictls/lib/pkgconfig:$HOME/nghttp3/lib/pkgconfig \ LDFLAGS="-Wl,-rpath,$HOME/quictls/lib" \ --prefix=$HOME/ngtcp2 \ --enable-lib-onlymake -j$(sysctl -n hw.logicalcpu)make installcd ..
#### 4. 编译 curlgit clone https://github.com/curl/curl --recurse-submodulescd curlautoreconf -fi./configure \ LDFLAGS="-Wl,-rpath,$HOME/quictls/lib" \ --with-openssl=$HOME/quictls \ --with-nghttp3=$HOME/nghttp3 \ --with-ngtcp2=$HOME/ngtcp2
make -j$(sysctl -n hw.logicalcpu)sudo make install # 需要管理员权限