Diary

Diary

日々学んだことをアウトプットする場として初めてみました

curlによるHTTP/3通信

curlによるHTTP/3通信

  • やったこと
    • SSLのインストール(http3は標準でsslを使用)
    • curlビルド時にSSLを紐付ける

現状確認

現在のMacに入っているVersionを確認する

$ curl -V
> curl 7.68.0 (x86_64-apple-darwin13.4.0) libcurl/7.68.0 OpenSSL/1.1.1d zlib/1.2.11 libssh2/1.8.2

この状態では、(helpで確認できるのにも関わらず)http3通信は行えない

$ curl --help | grep http3
>  --http3         Use HTTP v3
$ curl --http3 google.com
> curl: option --http3: the installed libcurl version doesn't support this
> curl: try 'curl --help' or 'curl --manual' for more information

curlインストール

事前準備として、Rustが必要

SSLのビルド

$ git clone https://github.com/cloudflare/quiche --recursive
$ cd quiche
$ cargo build --release --features ffi,pkg-config-meta,qlog
$ mkdir deps/boringssl/src/lib/
$ ln -vnf $(find target/release -name libcrypto.a -o -name libssl.a) deps/boringssl/src/lib

Curlのビルド

$ cd ..
$ git clone https://github.com/curl/curl.git
$ cd curl
$ ./buildconf
$ ./configure LDFLANGS="-Wl,-rpath,$PWD/../quiche/target/release" --with-ssl=$PWD/../quiche/target/release
$ make

確認してみると、下のようにちゃんと新しいバージョンが入っている。(unreleasedとかなってるけどええんか?)

$ ./src/curl -V   
> curl 7.78.0-DEV (x86_64-apple-darwin20.5.0) libcurl/7.78.0-DEV BoringSSL zlib/1.2.11 nghttp2/1.43.0 quiche/0.9.0
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: alt-svc AsynchDNS HSTS HTTP2 HTTP3 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets

BoringSSLとかも登録されてそうで、なんかうまくいきそうな予感

HTTP3通信を行ってみる

$ ./src/curl -v --http3 https://google.com
>
*   Trying 172.217.31.174:443...
* Connect socket 5 over QUIC to 172.217.31.174:443
* Sent QUIC client Initial, ALPN: h3,h3-29,h3-28,h3-27
* Connected to google.com () port 443 (#0)
* h3 [:method: GET]
* h3 [:path: /]
* h3 [:scheme: https]
* h3 [:authority: google.com]
* h3 [user-agent: curl/7.78.0-DEV]
* h3 [accept: */*]
* Using HTTP/3 Stream ID: 0 (easy handle 0x7fd8c980b600)
> GET / HTTP/3
> Host: google.com
> user-agent: curl/7.78.0-DEV
> accept: */*

なんかそれっぽいことしてそう

あとはデフォルトでこれを使いたければ、~/.vimrc~/.bashrcなどに、

alias curl='src/curlまでのフルパス --http3'

とかを追記しとけばよさそう