http3 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.clang-format +1 -0
- data/.vscode/extensions.json +6 -0
- data/.vscode/settings.json +10 -0
- data/CHANGELOG.md +34 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE-DEPENDENCIES.txt +66 -0
- data/LICENSE.txt +21 -0
- data/README.md +127 -0
- data/Rakefile +20 -0
- data/ext/http3/extconf.rb +48 -0
- data/ext/http3/nghttp3.c +347 -0
- data/ext/http3/nghttp3.h +105 -0
- data/ext/http3/nghttp3_callbacks.c +621 -0
- data/ext/http3/nghttp3_connection.c +1303 -0
- data/ext/http3/nghttp3_nv.c +87 -0
- data/ext/http3/nghttp3_qpack.c +656 -0
- data/ext/http3/nghttp3_settings.c +188 -0
- data/ext/http3/session.c +1017 -0
- data/lib/http3/rack_adapter.rb +162 -0
- data/lib/http3/request.rb +9 -0
- data/lib/http3/response.rb +21 -0
- data/lib/http3/server.rb +357 -0
- data/lib/http3/session.rb +193 -0
- data/lib/http3/version.rb +5 -0
- data/lib/http3.rb +16 -0
- data/sig/http3/nghttp3/callbacks.rbs +32 -0
- data/sig/http3/nghttp3/connection.rbs +101 -0
- data/sig/http3/nghttp3/error.rbs +48 -0
- data/sig/http3/nghttp3/info.rbs +9 -0
- data/sig/http3/nghttp3/nv.rbs +11 -0
- data/sig/http3/nghttp3/qpack.rbs +48 -0
- data/sig/http3/nghttp3/settings.rbs +27 -0
- data/sig/http3/rack_adapter.rbs +18 -0
- data/sig/http3/request.rbs +11 -0
- data/sig/http3/response.rbs +30 -0
- data/sig/http3/server.rbs +32 -0
- data/sig/http3/session.rbs +52 -0
- data/sig/http3.rbs +66 -0
- metadata +140 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7342e51b5150f53092806631b85d5d1053d16f7f757c26730227fd0a9d27619d
|
|
4
|
+
data.tar.gz: 7c7cee88475696117fcfe14e42333fc1267ffc0942c40360f6b6d0fcc9b487cf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 802c51e3f9040ac9d51ff0f6afee6e1541f7f479f94336283d49c346c127bf6740fca313ce4badb5627ba03e4793be9cd1536bafbfec24a180a3658a2a0c3cd7
|
|
7
|
+
data.tar.gz: fe45066ac7c54c622ff9c5fdab9d1fbc474867ce2076db6fd28f1c78ca4f65db8c5fbf1059b2dead1234e414902f8d43aa53c9912a08602fd0849425a5bfc480
|
data/.clang-format
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
BasedOnStyle: LLVM
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
## [0.0.3] - 2026-10-13
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
- `HTTP3::Server` serves a Rack 3 application over HTTP/3 on one UDP address: `HTTP3::Server.new(app:, bind:, certificate_path:, private_key_path:, **options).run`. Options: `transport_params`, `settings`, `qlog_dir`, `max_connections` (1024), `max_request_body` (1 MiB, 413 beyond), `max_field_section_size` (64 KiB, 431 beyond), `send_buffer_size` (64 KiB), `shutdown_timeout` (30 s) and `logger`. SIGTERM or SIGINT sends GOAWAY, refuses new connections and waits for the requests under way (a second signal stops waiting); SIGHUP reloads the certificate and key for new connections. Only failures are logged, as `event key=value ...` lines without query strings or header values. Response bodies may be files (`to_path`, read 16 KiB at a time), arrays (`to_ary`) or anything with `each`; streaming bodies (`call`) are answered with 500. Request fields whose names contain `_` are left out of the Rack env, so that they cannot pass for the dashed name (`x_forwarded_for` for `x-forwarded-for`). A response whose field names are not lowercase tokens, or whose field values contain NUL, CR or LF, is answered with 500. ([#5](https://github.com/unasuke/http3-ruby/pull/5))
|
|
5
|
+
- `HTTP3::Session`, HTTP/3 on one `QUIC::Connection::Server` through the quic gem's C function table; `HTTP3::RackAdapter`; and `HTTP3::Request`, `HTTP3::Response` and `HTTP3::Body`, the data passed between them. ([#5](https://github.com/unasuke/http3-ruby/pull/5))
|
|
6
|
+
- `HTTP3::Nghttp3::Connection#read_stream` takes `ts:`, the time in nanoseconds for nghttp3's rate limits (CLOCK_MONOTONIC by default), and now calls `nghttp3_conn_read_stream2`. ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
7
|
+
- `HTTP3::Nghttp3::Connection#shutdown_stream_read`, `#set_max_client_streams_bidi` and `#pending_data`. ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
8
|
+
- Tests of `HTTP3::RackAdapter`, of `HTTP3::Session` over a QUIC loopback connection, and of `HTTP3::Server` serving files and dynamic bodies and handling signals. An HTTP/3 interop check fetches from the server with curl in a container (`test/interop/curl.sh`), weekly in CI; `test/interop/README.md` describes the checks run by hand. ([#6](https://github.com/unasuke/http3-ruby/pull/6))
|
|
9
|
+
- The README documents installing http3 and running a Rack application on it: a launch script reading `config.ru`, the options, signals, logging and qlog, which responses get 500, and the Alt-Svc a TCP server has to send for browsers to find HTTP/3. `LICENSE-DEPENDENCIES.txt` reproduces the license terms of nghttp3 and sfparse, which are linked statically. ([#7](https://github.com/unasuke/http3-ruby/pull/7))
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- The gem is now `http3` (`require "http3"`), and the top-level namespace is `HTTP3`. The nghttp3 bindings move from `Nghttp3` to `HTTP3::Nghttp3`. No `Nghttp3` alias is left behind. ([#3](https://github.com/unasuke/http3-ruby/pull/3))
|
|
13
|
+
- nghttp3 is no longer taken from the system. Version 1.13.1 is downloaded and built at install time with mini_portile2 and linked statically, so `libnghttp3-dev` is no longer needed. http3.so exports only `Init_http3`; the nghttp3 symbols stay hidden. ([#3](https://github.com/unasuke/http3-ruby/pull/3))
|
|
14
|
+
- Ruby 3.3 or later is required, and only Linux is supported. ([#3](https://github.com/unasuke/http3-ruby/pull/3))
|
|
15
|
+
- http3 depends on the quic gem (`~> 0.0.3`) and, when loaded, looks up the C function table it publishes in `quic/ext.h`. A quic gem without a compatible table makes `require "http3"` raise `LoadError` naming the ABI version needed and the quic version found. ([#4](https://github.com/unasuke/http3-ruby/pull/4))
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
- The Ruby helpers on the bindings (`Nghttp3::Client`, `Server`, `Request`, `Response`, `Headers` and `StreamManager`). `HTTP3::Server` replaces the server side; the client side lives on in the tests only. ([#5](https://github.com/unasuke/http3-ruby/pull/5))
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- An exception raised by a callback block or a body block no longer unwinds through nghttp3's frames, which left nghttp3 in an inconsistent state. It is kept until nghttp3 returns and then raised from the method that called into it (`#read_stream`, `#writev_stream`, `#add_ack_offset`, ...). ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
22
|
+
- Body Strings are let go once the peer has acknowledged them, and when their stream closes. Before, a connection kept every body it ever sent. ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
23
|
+
- A body String is copied and frozen when submitted, and pinned until acknowledged, so neither the application nor `GC.compact` can change the bytes nghttp3 still reads. ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
24
|
+
- `GC.compact` could move a connection while nghttp3 held its address for callbacks. nghttp3 now gets a pointer to the C struct instead. ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
25
|
+
- `Connection.client_new` and `.server_new` raise `TypeError` for callbacks that are not an `HTTP3::Nghttp3::Callbacks`, instead of crashing in the first callback. ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
26
|
+
- The GC could crash collecting an `HTTP3::Nghttp3::QPACK::Decoder`: freeing its stream contexts walked a Hash the GC might already have freed, and read the contexts' addresses wrongly from it. ([#2](https://github.com/unasuke/http3-ruby/pull/2))
|
|
27
|
+
|
|
28
|
+
## [0.0.2] - 2026-10-13
|
|
29
|
+
|
|
30
|
+
- The last release as the `nghttp3` gem: its description says that the gem is no longer maintained. The code is that of 0.0.1.
|
|
31
|
+
|
|
32
|
+
## [0.0.1] - 2026-01-31
|
|
33
|
+
|
|
34
|
+
- Initial release, as the `nghttp3` gem
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Licenses of bundled dependencies
|
|
2
|
+
================================
|
|
3
|
+
|
|
4
|
+
The http3 gem downloads nghttp3 at install time, builds it on the installing
|
|
5
|
+
machine and links it into http3.so statically. It therefore redistributes no
|
|
6
|
+
third-party binaries; the terms are reproduced below for reference. The
|
|
7
|
+
QUIC layer comes from the quic gem, which carries its own
|
|
8
|
+
LICENSE-DEPENDENCIES.txt. The http3 gem itself is MIT licensed; see
|
|
9
|
+
LICENSE.txt.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
nghttp3 1.13.1 -- https://github.com/ngtcp2/nghttp3
|
|
13
|
+
---------------------------------------------------
|
|
14
|
+
|
|
15
|
+
The MIT License
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2019 nghttp3 contributors
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
20
|
+
a copy of this software and associated documentation files (the
|
|
21
|
+
"Software"), to deal in the Software without restriction, including
|
|
22
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
23
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
24
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
25
|
+
the following conditions:
|
|
26
|
+
|
|
27
|
+
The above copyright notice and this permission notice shall be
|
|
28
|
+
included in all copies or substantial portions of the Software.
|
|
29
|
+
|
|
30
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
31
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
32
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
33
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
34
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
35
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
36
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
37
|
+
|
|
38
|
+
Some nghttp3 source files also carry "Copyright (c) ngtcp2 contributors" or
|
|
39
|
+
"Copyright (c) nghttp2 contributors" notices, under the same terms.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
sfparse (bundled in nghttp3 1.13.1, lib/sfparse) -- https://github.com/ngtcp2/sfparse
|
|
43
|
+
-------------------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
The MIT License
|
|
46
|
+
|
|
47
|
+
Copyright (c) 2023 sfparse contributors
|
|
48
|
+
|
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
50
|
+
a copy of this software and associated documentation files (the
|
|
51
|
+
"Software"), to deal in the Software without restriction, including
|
|
52
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
53
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
54
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
55
|
+
the following conditions:
|
|
56
|
+
|
|
57
|
+
The above copyright notice and this permission notice shall be
|
|
58
|
+
included in all copies or substantial portions of the Software.
|
|
59
|
+
|
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
61
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
63
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
64
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
65
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
66
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yusuke Nakamura
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# http3-ruby
|
|
2
|
+
|
|
3
|
+
> [!CAUTION]
|
|
4
|
+
> This gem is for experimental purposes only. Do not use it in production environments.
|
|
5
|
+
|
|
6
|
+
> [!WARNING]
|
|
7
|
+
> The code in this repository is almost entirely generated by Claude Code and reviewed by a human.
|
|
8
|
+
|
|
9
|
+
`http3` serves Rack 3 applications over HTTP/3. It runs QUIC through the
|
|
10
|
+
[quic gem](https://github.com/unasuke/quic-ruby) and HTTP/3 through
|
|
11
|
+
[nghttp3](https://github.com/ngtcp2/nghttp3), which it builds from source and
|
|
12
|
+
links in statically. The nghttp3 bindings are also there to use directly, as
|
|
13
|
+
`HTTP3::Nghttp3`.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Linux only, Ruby 3.3 or later. Like the quic gem, installing builds C code, so
|
|
18
|
+
it needs a C compiler, pkg-config and the OpenSSL development package
|
|
19
|
+
(`build-essential pkg-config libssl-dev` on Debian and Ubuntu).
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle add http3
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
or, without Bundler:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
gem install http3
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
There is no `rackup` handler or command; start the server from a script:
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
# server.rb
|
|
37
|
+
require "http3"
|
|
38
|
+
require "rack"
|
|
39
|
+
|
|
40
|
+
app = Rack::Builder.parse_file("config.ru")
|
|
41
|
+
|
|
42
|
+
HTTP3::Server.new(
|
|
43
|
+
app: app,
|
|
44
|
+
bind: "192.0.2.1:443",
|
|
45
|
+
certificate_path: "/etc/tls/fullchain.pem",
|
|
46
|
+
private_key_path: "/etc/tls/privkey.pem"
|
|
47
|
+
).run
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`bind` is one address, `"host:port"` or `"[2001:db8::1]:443"`. It has to name
|
|
51
|
+
the address to serve: `0.0.0.0` and `[::]` are refused. The certificate file
|
|
52
|
+
is a PEM chain, leaf first, and the key a PEM key without passphrase.
|
|
53
|
+
|
|
54
|
+
Other options, with their defaults:
|
|
55
|
+
|
|
56
|
+
| Option | Default | |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| `max_connections:` | `1024` | Connections at once; more are refused with CONNECTION_REFUSED |
|
|
59
|
+
| `max_request_body:` | `1_048_576` | Bytes of request body; more gets 413 |
|
|
60
|
+
| `max_field_section_size:` | `65_536` | Bytes of request headers (RFC 9114 §4.2.2); more gets 431 |
|
|
61
|
+
| `send_buffer_size:` | `65_536` | Bytes of a response body queued but unsent per stream |
|
|
62
|
+
| `shutdown_timeout:` | `30` | Seconds a graceful stop waits for the requests under way |
|
|
63
|
+
| `qlog_dir:` | `nil` | Directory for one qlog file per connection |
|
|
64
|
+
| `transport_params:` | `QUIC::TransportParams.default` | QUIC transport parameters |
|
|
65
|
+
| `settings:` | `QUIC::Settings.default` | QUIC settings (the ALPN is always `h3`) |
|
|
66
|
+
| `logger:` | `Logger.new($stderr)` | Where failures are logged |
|
|
67
|
+
|
|
68
|
+
Response bodies may be files (`to_path`, sent 16 KiB at a time as the
|
|
69
|
+
connection takes them), arrays or anything with `each`. Streaming bodies
|
|
70
|
+
(`call`) are not supported and get 500, as do response headers whose names
|
|
71
|
+
are not lowercase tokens or whose values contain NUL, CR or LF.
|
|
72
|
+
|
|
73
|
+
### Signals
|
|
74
|
+
|
|
75
|
+
- `SIGTERM` or `SIGINT` stops gracefully: every client gets GOAWAY, new
|
|
76
|
+
connections are refused, and the server waits up to `shutdown_timeout`
|
|
77
|
+
seconds for the requests under way before closing every connection. A
|
|
78
|
+
second signal stops the wait.
|
|
79
|
+
- `SIGHUP` reads the certificate and key again; new connections use them,
|
|
80
|
+
existing ones keep theirs. If they cannot be loaded, the server keeps the
|
|
81
|
+
old ones and logs `tls_reload_failed`.
|
|
82
|
+
|
|
83
|
+
### Logging and qlog
|
|
84
|
+
|
|
85
|
+
Only failures are logged, one line each: the event, then `key=value` pairs.
|
|
86
|
+
Query strings and header values never appear. There is no access log; add
|
|
87
|
+
`Rack::CommonLogger` to your `config.ru` for one:
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
use Rack::CommonLogger
|
|
91
|
+
run MyApp
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`qlog_dir:` writes `<qlog_dir>/<connection ID>.sqlog` for every connection,
|
|
95
|
+
for tools such as [qvis](https://qvis.quictools.info/).
|
|
96
|
+
|
|
97
|
+
### Browsers
|
|
98
|
+
|
|
99
|
+
Browsers find HTTP/3 through an `Alt-Svc` header on an HTTP/1.1 or HTTP/2
|
|
100
|
+
response from the same host, so a TCP server there has to send
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
alt-svc: h3=":443"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
That is configured in that server (nginx, Puma, ...), not in this gem.
|
|
107
|
+
|
|
108
|
+
## Development
|
|
109
|
+
|
|
110
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
|
111
|
+
run `bundle exec rake` to build the extension, run the tests and lint. You can
|
|
112
|
+
also run `bin/console` for an interactive prompt.
|
|
113
|
+
|
|
114
|
+
`test/interop/` holds the checks against other HTTP/3 implementations (curl,
|
|
115
|
+
h3i, quic-interop-runner, browsers); see its README.
|
|
116
|
+
|
|
117
|
+
## Contributing
|
|
118
|
+
|
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/unasuke/http3-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/unasuke/http3-ruby/blob/main/CODE_OF_CONDUCT.md).
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). The licenses of the nghttp3 code built into it are in `LICENSE-DEPENDENCIES.txt`.
|
|
124
|
+
|
|
125
|
+
## Code of Conduct
|
|
126
|
+
|
|
127
|
+
Everyone interacting in the http3-ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unasuke/http3-ruby/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "minitest/test_task"
|
|
5
|
+
|
|
6
|
+
Minitest::TestTask.create
|
|
7
|
+
|
|
8
|
+
require "standard/rake"
|
|
9
|
+
|
|
10
|
+
require "rake/extensiontask"
|
|
11
|
+
|
|
12
|
+
task build: :compile
|
|
13
|
+
|
|
14
|
+
GEMSPEC = Gem::Specification.load("http3.gemspec")
|
|
15
|
+
|
|
16
|
+
Rake::ExtensionTask.new("http3", GEMSPEC) do |ext|
|
|
17
|
+
ext.lib_dir = "lib/http3"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
task default: %i[clobber compile test standard]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "mkmf"
|
|
4
|
+
require "mini_portile2"
|
|
5
|
+
|
|
6
|
+
# nghttp3 is downloaded and built at install time and linked statically, so
|
|
7
|
+
# installing needs no system package and always gets this version.
|
|
8
|
+
# nghttp3_conn_read_stream2 needs 1.12.0 or later. nghttp3 depends on nothing
|
|
9
|
+
# but libc, so its version does not have to follow the quic gem's ngtcp2.
|
|
10
|
+
NGHTTP3_VERSION = "1.13.1"
|
|
11
|
+
NGHTTP3_SHA256 = "07160f28af3ddc3e8b95c8bbefe08c650e7cf303375141b6ca35cc89b319f70d"
|
|
12
|
+
|
|
13
|
+
nghttp3 = MiniPortile.new("nghttp3", NGHTTP3_VERSION)
|
|
14
|
+
nghttp3.files = [{
|
|
15
|
+
url: "https://github.com/ngtcp2/nghttp3/releases/download/v#{NGHTTP3_VERSION}/nghttp3-#{NGHTTP3_VERSION}.tar.gz",
|
|
16
|
+
sha256: NGHTTP3_SHA256
|
|
17
|
+
}]
|
|
18
|
+
# The release tarball ships configure, so no autotools are needed.
|
|
19
|
+
nghttp3.configure_options = [
|
|
20
|
+
"--enable-lib-only",
|
|
21
|
+
"--disable-shared",
|
|
22
|
+
"--with-pic"
|
|
23
|
+
]
|
|
24
|
+
nghttp3.cook
|
|
25
|
+
|
|
26
|
+
nghttp3.mkmf_config(static: "nghttp3")
|
|
27
|
+
# Without it, nghttp3.h declares the functions for a shared library.
|
|
28
|
+
append_cflags("-DNGHTTP3_STATICLIB")
|
|
29
|
+
|
|
30
|
+
abort "nghttp3/nghttp3.h not found" unless have_header("nghttp3/nghttp3.h")
|
|
31
|
+
abort "libnghttp3 not linkable" unless have_func("nghttp3_version", "nghttp3/nghttp3.h")
|
|
32
|
+
|
|
33
|
+
# The quic gem's C function table, through which HTTP3::Session drives a
|
|
34
|
+
# QUIC connection. The header ships in the quic gem; the table itself is
|
|
35
|
+
# looked up at load time with rb_ext_resolve_symbol (Ruby 3.3 or later).
|
|
36
|
+
require "quic/ext_include"
|
|
37
|
+
append_cppflags("-I#{QUIC::EXT_INCLUDE_DIR}")
|
|
38
|
+
abort "quic/ext.h not found (the quic gem 0.0.3 or later provides it)" unless have_header("quic/ext.h")
|
|
39
|
+
abort "rb_ext_resolve_symbol not found (Ruby 3.3 or later is required)" unless
|
|
40
|
+
have_func("rb_ext_resolve_symbol", "ruby.h")
|
|
41
|
+
|
|
42
|
+
# Makes all symbols private by default to avoid unintended conflict
|
|
43
|
+
# with other gems. To explicitly export symbols you can use RUBY_FUNC_EXPORTED
|
|
44
|
+
# selectively, or entirely remove this flag.
|
|
45
|
+
append_cflags("-fvisibility=hidden")
|
|
46
|
+
append_ldflags("-Wl,--exclude-libs,ALL") # Unexport symbols from the static nghttp3
|
|
47
|
+
|
|
48
|
+
create_makefile("http3/http3")
|