👋
【Ruby】Falcon で HTTP/2 サーバーを利用する
HTTP/2 サーバーの Falcon を導入してみた。gem でのインストールは次のとおり
gem install falcon
config.ru
を用意する
config.ru
run do |env|
[200, {'Content-Type' => 'text/plain'}, ['Hello, World!']]
end
サーバーを起動させる
falcon serve
自己署名の証明書は自動的に生成される。デフォルトポートは 9292 である。curl でリクエストを送信すると HTTP/2 に対応していることがわかる
curl -v -k https://localhost:9292
* Trying 127.0.0.1:9292...
* Connected to localhost (127.0.0.1) port 9292 (#0)
* ALPN: offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN: server accepted h2
* Server certificate:
* subject: O=Development; CN=localhost
* start date: Jul 2 10:16:05 2024 GMT
* expire date: Jul 2 10:16:05 2025 GMT
* issuer: O=Development; CN=localhost
* SSL certificate verify result: self-signed certificate (18), continuing anyway.
* using HTTP/2
* h2h3 [:method: GET]
* h2h3 [:path: /]
* h2h3 [:scheme: https]
* h2h3 [:authority: localhost:9292]
* h2h3 [user-agent: curl/7.88.1]
* h2h3 [accept: */*]
* Using Stream ID: 1 (easy handle 0x557c3d503ce0)
> GET / HTTP/2
> Host: localhost:9292
> user-agent: curl/7.88.1
> accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
< HTTP/2 200
< content-length: 13
< content-type: text/plain
< vary: accept-encoding
<
* Connection #0 to host localhost left intact
Hello, World!
Discussion