connectrpc-hyper 0.3.0-x86_64-linux

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8a8564836882665a96b25f2025e9746746ccb19c1b97ae167b6e54eb87e9780f
4
+ data.tar.gz: f31b183df7293ba42808600362edcae461b87a7a57f011c83099026ea98532e7
5
+ SHA512:
6
+ metadata.gz: 9b896b39d28bc08a2ea0a07b7aa7f9c6b6e9c76140d66e2393c9255913ce005c7cfa976d7c7f016bbbb46a1c5e518a8d17230bc6acd5626aeea3d660ee4f0364
7
+ data.tar.gz: a1f8887ab50bf3c80978b26814b4df20cbca000a8a4a7c836b5860a1d80bd2a2f0cea68a7a4dfdd4cc21c31f06ce4ee42d580f0eaa3212f75659c903e422f611
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jim Myhrberg
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,475 @@
1
+ <div align="center">
2
+
3
+ <img height="128px" width="128px" src="../../img/connectrpc-ruby.svg" alt="connectrpc-ruby logo">
4
+
5
+ # connectrpc-hyper
6
+
7
+ **A reactor-free ConnectRPC client transport on Rust's hyper, h2 and rustls.**
8
+
9
+ [![RubyGems](https://img.shields.io/gem/v/connectrpc-hyper?logo=rubygems&logoColor=white&label=RubyGems)](https://rubygems.org/gems/connectrpc-hyper)
10
+ [![CI](https://img.shields.io/github/actions/workflow/status/jimeh/connectrpc-ruby/ci.yml?branch=main&logo=github&label=CI)](https://github.com/jimeh/connectrpc-ruby/actions/workflows/ci.yml)
11
+ [![Docs](https://img.shields.io/badge/Docs-guides-0969da?logo=markdown&logoColor=white)](https://github.com/jimeh/connectrpc-ruby/tree/main/docs)
12
+ [![License](https://img.shields.io/github/license/jimeh/connectrpc-ruby?label=License)](https://github.com/jimeh/connectrpc-ruby/blob/main/LICENSE)
13
+
14
+ </div>
15
+
16
+ `connectrpc-hyper` is an optional client transport for
17
+ [connectrpc](https://github.com/jimeh/connectrpc-ruby). Since 0.3.0,
18
+ `ConnectRPC::Hyper::Transport` lets any Ruby thread make Connect and native
19
+ gRPC calls of all four shapes over HTTP/2, and Connect calls over HTTP/1.1,
20
+ without an Async reactor. A native extension built on hyper, h2, rustls with
21
+ the aws-lc-rs provider and tokio owns connections, streams and blocking waits.
22
+ Ruby keeps the protocol logic, deadlines, cancellation and error phrases.
23
+
24
+ The package is experimental and follows the release train's version. See the
25
+ [supported 0.x contract](../../docs/support.md) for the support profile and the
26
+ platforms that were built, installed and exercised.
27
+
28
+ ## Installation
29
+
30
+ ```ruby
31
+ gem "connectrpc-hyper", "~> 0.3.0"
32
+ ```
33
+
34
+ The runtime dependency is `connectrpc ~> 0.3.0`. The transport never loads
35
+ connectrpc-async, Rack or Google protobuf.
36
+
37
+ ### Prebuilt platform gems
38
+
39
+ Platform gems carry the extension for Ruby 3.4 and 4.0 and install without
40
+ Rust or a compiler:
41
+
42
+ | Platform | Requirement |
43
+ | --- | --- |
44
+ | `x86_64-linux`, `aarch64-linux` | glibc 2.29 or later |
45
+ | `x86_64-linux-musl`, `aarch64-linux-musl` | musl with `libgcc_s` (Alpine: the `libgcc` package) |
46
+ | `arm64-darwin` | macOS 11 or later |
47
+ | `x86_64-darwin` | Intel macOS; the binaries declare macOS 10.13, and CI smoke-tests them on macOS 15 |
48
+ | `x64-mingw-ucrt` | Windows x64, provisional (see [support](../../docs/support.md)) |
49
+ | `aarch64-mingw-ucrt` | Windows arm64, provisional (see [support](../../docs/support.md)) |
50
+
51
+ ### Source gem
52
+
53
+ Elsewhere RubyGems installs the source gem, which compiles the extension at
54
+ install time with your `cargo`. It needs Rust 1.85 or later (the declared
55
+ `rust-version`), libclang for rb-sys's bindgen and a C compiler. The build uses
56
+ the packaged `Cargo.lock` with `--locked`, and set `CARGO_NET_OFFLINE=true` to
57
+ build from a pre-fetched crate cache. The source gem also depends on `rb_sys`
58
+ (`>= 0.9.130, < 1`); platform gems drop it. The extension is about 6 MB per
59
+ Ruby minor.
60
+
61
+ ## Usage
62
+
63
+ ```ruby
64
+ require "connectrpc/hyper"
65
+
66
+ transport = ConnectRPC::Hyper::Transport.new
67
+ client = ConnectRPC::Client.new(base_url: "https://api.example.com", transport: transport, protocol: :grpc)
68
+ # Generated clients take the same core client. Share one transport between threads.
69
+ transport.close(grace: 5) # => true when every in-flight call drained
70
+ ```
71
+
72
+ Construction validates every option, raises `ArgumentError` for invalid ones
73
+ and starts no thread or socket. `inspect` shows the connection mode, `http2`,
74
+ whether TLS options are set and the state, never paths, key material or proxy
75
+ URLs.
76
+
77
+ | Option | Default | Meaning |
78
+ | --- | --- | --- |
79
+ | `connections:` | `:pooled` | `:pooled` shares one admitting connection per origin; `:per_call` opens one per call. |
80
+ | `idle_timeout:` | `1800` | Seconds before a pooled connection with no calls in flight closes; nil keeps it. |
81
+ | `keepalive:` | `nil` | A `ConnectRPC::Keepalive`; see [keepalive](#keepalive). |
82
+ | `http2:` | `true` | `false` sends Connect over HTTP/1.1 only. |
83
+ | `connect_timeout:` | `10` | Seconds for DNS, TCP, proxy `CONNECT`, TLS and the HTTP/2 handshake. Must be finite, as connectrpc-async requires, so every dial ends on its own. Each address of a host gets a share; see [connections](#connections-and-server-restarts). |
84
+ | `ca_file:` | `nil` | PEM file appended to the trusted roots. |
85
+ | `certificate_chain:` | `nil` | Client certificate chain, an Array of PEM strings, leaf first. |
86
+ | `private_key:` | `nil` | Client key as a PEM string; required with `certificate_chain:`. |
87
+ | `proxy:` | `:environment` | See [proxies](#proxies). |
88
+
89
+ Durations accept any finite positive number. Native code caps each one (and
90
+ `close(grace:)`) at about 115 days (9,999,999.999 seconds, the largest
91
+ `connect-timeout-ms`), so a larger value behaves as that cap.
92
+
93
+ `streaming_capabilities` is `[:server_stream, :client_stream, :bidi_stream]`
94
+ with HTTP/2 and `[:server_stream, :client_stream]` with `http2: false`.
95
+ `grpc_capabilities` is all four shapes with HTTP/2 and empty with
96
+ `http2: false`, so core rejects those calls before they reach the transport.
97
+
98
+ ## Which transport
99
+
100
+ - Core `ConnectRPC::Transports::NetHTTP` is enough for simple Connect unary
101
+ calls. It has no dependencies and opens one connection per call.
102
+ - `ConnectRPC::Hyper::Transport` serves any thread (Puma, Sidekiq, scripts)
103
+ with pooled HTTP/2, every call shape and native gRPC.
104
+ - connectrpc-async's `Transport` and `ThreadedTransport` suit applications
105
+ already on Async, or ones that need its connection policy (backoff,
106
+ `wait_for_ready`, admission budgets) and connection observers.
107
+ - connectrpc-async's `PerCallTransport` makes calls from inside an Async
108
+ reactor. A hyper call there blocks the reactor thread, unless Ruby 4.0 and
109
+ async's opt-in worker pool offload it; see
110
+ [fiber schedulers](#fiber-schedulers).
111
+
112
+ ## Connections and server restarts
113
+
114
+ One HTTP/2 connection per origin and transport admits new calls. When there
115
+ is none, the transport starts one dial for the origin, owned by the transport
116
+ rather than by any call, and every caller that finds no connection waits for
117
+ that dial. As in a grpc-go channel, its outcome is the same for every waiter:
118
+ the new connection, or the failure. A pooled connection that ends before the
119
+ server's HTTP/2 preface (its SETTINGS frame) fails the dial's waiters with
120
+ that connection's failure instead of dialing again, as grpc-go treats a
121
+ transport that never received the server preface as a failed connection
122
+ attempt. So a server that ends every connection right after its handshake,
123
+ such as a TLS 1.3 server rejecting a missing client certificate, cannot keep
124
+ a caller dialing until its deadline. A connection that closes or drains
125
+ after the preface, such as one that received a graceful GOAWAY, was working:
126
+ its waiters dial again, as grpc-go re-picks a transport, and so do the
127
+ waiters of a connection the idle timeout closed. A waiter's own deadline,
128
+ cancellation or interrupt ends only its wait. A call with a short deadline
129
+ fails `deadline_exceeded` while the dial carries on and pools its connection
130
+ for later calls. A second HTTP/2 connection never replaces a usable pooled
131
+ one: it serves only the call that dialed it, then closes. hyper multiplexes calls
132
+ up to the peer's `SETTINGS_MAX_CONCURRENT_STREAMS`. Behaviour compared with a
133
+ grpc-go channel:
134
+
135
+ - An idle connection answers server PINGs and processes GOAWAY without a call
136
+ in flight.
137
+ - After a graceful GOAWAY (a server restart or `MaxConnectionAge`), the
138
+ connection stops admitting and drains its open streams up to the GOAWAY's
139
+ last stream id, which finish normally. The next call dials a new
140
+ connection. A stream above the last stream id was never processed
141
+ (RFC 9113 section 6.8), so it is retried within the limits below, as
142
+ grpc-go retries it. A server that drains in two steps first names the
143
+ highest possible stream id, which disowns nothing; its eligible streams
144
+ are retried once its final GOAWAY names a lower one.
145
+ - After a hard kill, calls in flight fail `unavailable` with
146
+ `HTTP transport failed: connection closed`. Once the transport has read
147
+ the reset, the next call reconnects; a call that starts before then can
148
+ still go to the dead connection. If hyper had not taken its request yet,
149
+ it hands it back and the call is retried (below); once hyper took it, the
150
+ call fails the same way. grpc-go also retries a call whose headers its
151
+ writer had not yet attempted; hyper does not report that, so this
152
+ transport does not.
153
+ - A peer that goes silent without closing the socket is only detected by
154
+ [keepalive](#keepalive) or the call deadline.
155
+ - Reconnection is lazy. There is no `wait_for_ready`, no background reconnect
156
+ and no backoff: a call that cannot connect fails at once with the connect
157
+ phrase, and the next call dials again. connectrpc-async's connection policy
158
+ offers backoff and `wait_for_ready`.
159
+ - `idle_timeout` (grpc-go's 30 minutes) closes a pooled connection with no
160
+ calls in flight. The timer claims the exact connection it saw idle, so it
161
+ never closes a connection a caller has just checked out, and a connection
162
+ closes only after a full `idle_timeout` without calls.
163
+ - A request waiting inside hyper for a `SETTINGS_MAX_CONCURRENT_STREAMS`
164
+ slot already has a stream id but never reached the wire. When a GOAWAY's
165
+ last stream id falls below that id, it is retried on any call shape, as
166
+ are requests still in hyper's own queue (below). hyper drops such a request
167
+ on a server's first GOAWAY, which may name the highest possible stream id.
168
+ Unless the final GOAWAY's lower last stream id has already arrived by then,
169
+ it fails `unavailable` (`HTTP transport failed: connection closed`).
170
+
171
+ `connections: :per_call` dials a fresh connection for every call and closes it
172
+ afterwards. With `http2: false`, each call dials its own connection, in
173
+ parallel, as Go's `net/http` dials them, since one HTTP/1.1 connection serves
174
+ one call at a time. When TLS negotiates `http/1.1` for an `http2: true`
175
+ transport, each caller that waited for that dial uses a usable pooled or idle
176
+ connection if there is one, such as the clean connection that dial parked,
177
+ and otherwise dials its own; a streaming call, which needs HTTP/2, fails with
178
+ the ALPN phrase instead. A later burst that finds no idle connection waits for one
179
+ shared dial again. Pooling keeps at most two idle keep-alive connections per
180
+ origin (Go's `DefaultMaxIdleConnsPerHost`); only a connection whose request
181
+ and response both completed returns to the pool.
182
+
183
+ Requests the server never processed are retried once on a fresh connection,
184
+ within the original deadline and with the wire timeout recomputed:
185
+
186
+ - on any call shape, a request that never reached the wire: one hyper hands
187
+ back unsent, or one whose stream id is above a GOAWAY's last stream id and
188
+ whose HEADERS never reached the socket (a streaming request also needs its
189
+ body unread);
190
+ - a Connect unary call, before response headers, that the server refused with
191
+ `REFUSED_STREAM` or whose stream id is above a GOAWAY's last stream id.
192
+
193
+ tokio's request channel can keep a request sent just as hyper's dispatcher
194
+ ends: never received and never answered. Since hyper 1.13.0 a dispatcher that
195
+ shuts down waits for such a request and hands it back. A request can still be
196
+ stranded when a forced close stops the dispatcher before it finishes, or when
197
+ an HTTP/1.1 connection ends in an upgrade. The transport detects one once the
198
+ dispatcher is gone, as Go's `net/http` watches a connection's close while it
199
+ waits for a response. A Connect unary call treats it as handed back unsent,
200
+ within the retry above. A streaming call, gRPC unary included, fails with its
201
+ connection's failure, since its body cannot be recovered, and a `write`
202
+ blocked on that body returns.
203
+
204
+ Nothing else is replayed, so a handler that started never runs twice. After
205
+ a GOAWAY, a stream at or below its last stream id is never replayed; a
206
+ `REFUSED_STREAM` refusal still is, since RFC 9113 section 8.7 says that
207
+ stream was not processed. Nor is a gRPC call whose HEADERS were sent, since
208
+ `open_grpc_stream` cannot tell unary from streaming. hyper and h2 report
209
+ neither stream ids nor the last stream id, so the transport derives each
210
+ request's stream id from the order hyper hands requests to h2 and reads the
211
+ last stream id off the connection's HTTP/2 frame headers. The server's GOAWAY
212
+ is the authority on what it processed, as its `REFUSED_STREAM` is; a
213
+ malformed GOAWAY, or one that raises the last stream id, ends GOAWAY retries
214
+ on that connection. A Connect unary call whose HEADERS were sent is replayed
215
+ only when h2 itself failed its stream for a GOAWAY. A call canceled before
216
+ its retry is queued is not retried. When the pooled connection that refused
217
+ or handed back the request still admits calls, it stays pooled for them and
218
+ the retry dials a connection that serves only that call. A connection that
219
+ received GOAWAY admits nothing more, so its retries share the next pool dial.
220
+
221
+ Hostnames resolve through tokio's blocking pool (`getaddrinfo`), capped at
222
+ 512 threads, close to Go's 500 cgo lookup threads. A stalled lookup keeps its
223
+ thread after the caller leaves. Addresses of both families are tried with Go's
224
+ 300 ms fallback delay. Within one family, addresses are tried in turn, each
225
+ within an equal share of what is left of the setup budget, but at least 2
226
+ seconds (Go's `partialDeadline`, as NetHTTP's dialer does), so a blackholed
227
+ first address does not use up the whole budget. The shared HTTP/2 dial's
228
+ budget is `connect_timeout`; a dial that serves one call (per-call mode,
229
+ `http2: false`, a call after an `http/1.1` outcome, or a retry that leaves a
230
+ pooled connection in place) gets the earlier of `connect_timeout` and its
231
+ call's deadline. A call whose deadline ends during setup still fails
232
+ `deadline_exceeded`. A shared dial still running when its transport is
233
+ garbage collected ends within `connect_timeout`.
234
+
235
+ ## Keepalive
236
+
237
+ ```ruby
238
+ keepalive = ConnectRPC::Keepalive.new(time: 60, timeout: 20, permit_without_calls: false)
239
+ transport = ConnectRPC::Hyper::Transport.new(keepalive: keepalive)
240
+ ```
241
+
242
+ `ConnectRPC::Keepalive` is core's value (Since 0.3.0); connectrpc-async's
243
+ `ConnectRPC::Async::Keepalive` is the same class. It maps to hyper's
244
+ `keep_alive_interval`, `keep_alive_timeout` and `keep_alive_while_idle`. After
245
+ `time` seconds without a read, the transport sends a PING. Without its ACK
246
+ within `timeout`, the connection retires, its calls fail `unavailable` and the
247
+ next call reconnects. hyper's clock differs from grpc-go's:
248
+
249
+ - It resets on response HEADERS, on DATA and trailers as Ruby consumes them,
250
+ and on PING ACKs. Server PINGs, SETTINGS and WINDOW_UPDATE do not reset it,
251
+ so it may ping earlier than grpc-go.
252
+ - DATA that arrived while the peer went silent moves the clock only once Ruby
253
+ reads it, so a stalled reader can see detection later than grpc-go would.
254
+ - Without `permit_without_calls`, a connection with no calls is never probed.
255
+ - Keepalive and BDP flow control share one outstanding PING.
256
+
257
+ A server's keepalive enforcement (grpc-go's `MinTime`, 5 minutes by default)
258
+ can close connections that ping more often; choose `time` to match the server.
259
+
260
+ ## Interrupts, deadlines and cancellation
261
+
262
+ Waits release the GVL. `Thread#raise`, `Thread#kill`, `Timeout.timeout`, the
263
+ call deadline and a cancellation token stop a call during name resolution,
264
+ connect, TLS, a blocked write and a blocked read. The stream is reset with
265
+ `CANCEL`, so the peer sees `RST_STREAM(CANCEL)`, and the shared connection
266
+ keeps serving other calls. A token cancels name resolution, connect and TLS,
267
+ including a wait for the shared dial (which carries on for other callers). The wire timeout headers
268
+ (`grpc-timeout`, `connect-timeout-ms`) carry the deadline remaining at dispatch,
269
+ after connection setup and on a retry.
270
+
271
+ ## Fiber schedulers
272
+
273
+ Inside an Async reactor, a call blocks the reactor thread, and with it every
274
+ sibling task, until it finishes. On Ruby 4.0 with async's opt-in worker pool
275
+ (`ASYNC_SCHEDULER_WORKER_POOL=true` or
276
+ `Async::Scheduler.new(worker_pool: true)`), the wait moves to a worker thread:
277
+ sibling tasks keep running, and `Task#stop`, cancellation, deadlines,
278
+ `Thread#raise` and `Thread#kill` still land. async creates io-event's worker
279
+ pool with one worker by default, so parked waits from different tasks run one
280
+ at a time: a second task's wait queues until the first one's ends. Pass
281
+ `Async::Scheduler.new(worker_pool: IO::Event::WorkerPool.new(maximum_worker_count: N))`
282
+ for more workers. Waits offer a fiber scheduler's `blocking_operation_wait`
283
+ hook only on Ruby 4.0 and later, whose blocking-operation API lets io-event
284
+ finish a running wait before it raises a cancellation. Ruby 3.4 hands the hook
285
+ a plain proc, so a cancelled scheduler could unwind the call while its wait
286
+ still runs on a worker; there calls always block the reactor, whatever the
287
+ scheduler. Use connectrpc-async's transports for calls from inside a reactor.
288
+
289
+ `close` is the exception. Called from a non-blocking fiber under a fiber
290
+ scheduler, on Ruby 3.4 and 4.0 alike, it waits for teardown on a helper
291
+ thread, taking neither the reactor thread nor a worker of the pool, so sibling
292
+ tasks keep running and their in-flight calls can drain within the grace. A
293
+ closer inside `Fiber.blocking {}`, or one whose helper thread cannot start
294
+ (`ThreadError`), waits on its own thread and holds the reactor until teardown
295
+ ends.
296
+
297
+ ## Fork
298
+
299
+ The tokio runtime has two `hyper-runtime` worker threads plus tokio's blocking
300
+ pool, created lazily on the first call in each process. A forked child never
301
+ touches its parent's runtime or connections: it builds its own on first use.
302
+ The child closes, never shuts down, the inherited connection sockets it can
303
+ identify, so the parent's connections keep working and a long-lived child does
304
+ not hold them open. A socket still connecting at the moment of fork is not
305
+ identified and stays open in the child until it exits. A transport closed
306
+ before fork stays closed in the child.
307
+
308
+ ## TLS
309
+
310
+ Native roots come from the platform store through rustls-native-certs, loaded
311
+ once per process. `SSL_CERT_FILE` or `SSL_CERT_DIR` replaces the platform store
312
+ rather than adding to it. `ca_file` appends its certificates to whichever roots
313
+ were selected. TLS 1.2 is the minimum, session resumption is off, ALPN offers
314
+ `h2, http/1.1` (`http/1.1` with `http2: false`) and IP literals get no SNI.
315
+
316
+ Inputs are validated in Ruby with OpenSSL, as core NetHTTP validates them. An
317
+ invalid input raises `ArgumentError` naming only the input, for example
318
+ `Invalid TLS client configuration: private_key`, with no `cause`. A TLS option
319
+ on an `http://` request raises `ArgumentError, "TLS options require an HTTPS
320
+ origin"`. rustls is stricter than OpenSSL:
321
+
322
+ - CN-only server certificates (without a matching SAN), X.509 v1
323
+ certificates, a wildcard over a single label and a CA certificate used as the
324
+ server certificate fail with `HTTP transport failed: TLS verification failed`.
325
+ - Encrypted private keys are not accepted.
326
+ - A key OpenSSL accepts but aws-lc-rs cannot sign with, such as Ed448, fails at
327
+ construction with the `private_key` error.
328
+ - `ca_file` is read with OpenSSL's store semantics, as NetHTTP reads it: a
329
+ CRL-only file adds no roots, and trust settings in `TRUSTED CERTIFICATE`
330
+ blocks are dropped. A `ca_file` certificate that rustls cannot use as a
331
+ trust anchor is rejected at construction.
332
+
333
+ ## HTTP/1.1 and ALPN
334
+
335
+ `http2: false` sends Connect unary, server-streaming and client-streaming calls
336
+ over HTTP/1.1, cleartext or TLS. With `http2: true`, every streaming call needs
337
+ h2: when TLS negotiates `http/1.1`, `open_stream` and `open_grpc_stream` fail
338
+ `unavailable` (`HTTP transport failed: ALPN negotiation failed`) before any
339
+ request is sent, so the server sees no application request. While the origin's
340
+ pool holds an idle HTTP/1.1 connection from such a negotiation, a streaming call
341
+ fails with the same phrase without dialing. Connect unary calls proceed over
342
+ HTTP/1.1. Cleartext `http://` with HTTP/2 uses prior knowledge (h2c).
343
+
344
+ ## Proxies
345
+
346
+ `proxy:` follows core NetHTTP's rules (Since 0.3.0); the
347
+ [NetHTTP proxy guide](../../docs/unary.md#nethttp-tls-and-proxies) has the full
348
+ environment and `NO_PROXY` semantics.
349
+
350
+ - `proxy: :environment`, the default, snapshots `HTTP_PROXY`, `HTTPS_PROXY`,
351
+ `NO_PROXY` and their lowercase forms when the transport is constructed and
352
+ applies Go 1.27.3's rules through core's resolver. `localhost` and loopback
353
+ addresses never use the environment proxy, and in a CGI process
354
+ (`REQUEST_METHOD` set) `HTTP_PROXY` fails `http://` calls instead of being
355
+ trusted.
356
+ - A String or URI proxies every request, including loopback and `NO_PROXY`
357
+ hosts. `proxy: nil` always connects directly.
358
+ - Only `http://` proxies are supported, with Basic `Proxy-Authorization` from
359
+ the URL's percent-decoded userinfo. An explicit invalid or unsupported proxy
360
+ raises `ArgumentError` (`Invalid proxy configuration` or
361
+ `Unsupported proxy scheme`) with no cause. A problem with an environment
362
+ proxy fails the affected calls with `unavailable` and NetHTTP's fixed phrases
363
+ (`invalid proxy address`, `unsupported proxy scheme`,
364
+ `proxy refused in CGI environment`) before any socket opens, and never falls
365
+ back to a direct connection.
366
+ - h2c and TLS targets tunnel through `CONNECT`, as grpc-go does; TLS verifies
367
+ the target host, not the proxy. Plaintext HTTP/1.1 (`http2: false`) requests
368
+ to `http://` targets go to the proxy in absolute form, as NetHTTP and Go's
369
+ `net/http` send them, so proxies that allow `CONNECT` only to port 443 still
370
+ work. A forwarding proxy handles each request as an HTTP intermediary:
371
+ streaming calls over this path depend on it passing chunked bodies through
372
+ incrementally. TLS targets always tunnel, end to end.
373
+ - The environment proxy is chosen by the target URL's scheme, as Go's
374
+ `net/http` and NetHTTP choose it: an h2c target is `http://`, so it takes
375
+ `HTTP_PROXY`. grpc-go instead looks proxies up with an `https` scheme for
376
+ every target, so it would use `HTTPS_PROXY` for the same h2c target.
377
+ - A `CONNECT` exchange reads at most a 10 MiB reply head within 60 seconds, as
378
+ in Go, and needs exactly status 200. For TLS and HTTP/1.1 targets no bytes
379
+ may follow the reply head, as in NetHTTP; for h2c they may, because an h2c
380
+ server can send its SETTINGS right behind the proxy's reply, and grpc-go
381
+ keeps such bytes. Failures are `unavailable` with
382
+ `proxy authentication failed` (407), `proxy tunnel refused`,
383
+ `proxy tunnel failed` or `proxy tunnel timed out`, and proxy reply bytes
384
+ never reach errors. The call deadline, cancellation, interrupts and
385
+ `connect_timeout` also cover the proxy hop; an earlier deadline still ends
386
+ the call with `deadline_exceeded`.
387
+ - Pooled connections are kept per origin and proxy route (proxy address and
388
+ credentials), so direct and proxied calls never share a connection.
389
+ `inspect` shows only `proxy=environment`, `explicit` or `direct`, never the
390
+ proxy URL or credentials.
391
+ - The native code never reads proxy variables itself; Ruby resolves the proxy
392
+ for each request, and `cargo deny` rejects hyper-util's proxy features.
393
+ - Compared with Go: `CONNECT` sends no `User-Agent` (Go sends
394
+ `Go-http-client/1.1`), forwarded HTTP/1.1 connections are not shared across
395
+ targets, and HTTPS and SOCKS proxies are not supported.
396
+
397
+ Core's default `User-Agent` reaches the wire unchanged, and caller metadata
398
+ that sets `user-agent` wins.
399
+
400
+ ## Limits
401
+
402
+ - A Connect unary response larger than the call's response limit fails
403
+ `resource_exhausted` (`Response exceeds byte limit`), whether the
404
+ `content-length` advertises it or the body grows past it.
405
+ - gRPC response headers and trailers are limited to core's 65,536 bytes of
406
+ regular fields (`gRPC field block exceeds byte limit`), and outbound gRPC
407
+ metadata over the limit fails before dispatch. h2 itself accepts header
408
+ blocks up to 16 MiB, grpc-go's default, so a hostile block above that can
409
+ still truncate trailers.
410
+ - An HTTP/1.1 response head (status line and fields) may be up to 10 MiB, the
411
+ bound Go's `MaxResponseHeaderBytes` default puts on the response head, in
412
+ bytes only. This transport applies the same 10 MiB cap to chunked trailers,
413
+ its own choice. hyper also counts fields, so this transport accepts up to
414
+ 1,024 of them in a head or in trailers; hyper's own defaults (100 fields,
415
+ about 400 KiB) are lower. A larger head or trailer block fails with
416
+ `malformed response`.
417
+ - Streaming messages follow core's message limits. Flow control uses BDP
418
+ adaptive windows capped at 16 MiB like grpc-go, and each stream buffers at
419
+ most 1 MiB of unsent request data, so `write` blocks while the peer does not
420
+ read, until the deadline.
421
+
422
+ ## Errors
423
+
424
+ Transport failures are `unavailable` with a fixed message and the native
425
+ failure as `cause`:
426
+
427
+ | Message | Failure |
428
+ | --- | --- |
429
+ | `HTTP transport failed: name resolution failed` | DNS |
430
+ | `HTTP transport failed: connection refused` | TCP refused |
431
+ | `HTTP transport failed: host unreachable` / `connection failed` | Other connect errors |
432
+ | `HTTP transport failed: timed out` | `connect_timeout` |
433
+ | `HTTP transport failed: TLS verification failed` / `TLS error` | Certificate or handshake failure, or a TLS rejection the server sends after the handshake (such as for a missing client certificate) when the connection that fails the call has read it. A connection whose write fails first reports `connection closed`, as grpc-go reports a write error. A call retried after its first connection read the rejection reports its retry connection's failure |
434
+ | `HTTP transport failed: ALPN negotiation failed` | Streaming call on an HTTP/1.1 TLS connection |
435
+ | `HTTP transport failed: connection closed` | The connection closed, retired or received GOAWAY |
436
+ | `HTTP transport failed: malformed response` | Protocol error |
437
+ | `HTTP transport failed: stream reset` | A Connect stream reset by the server |
438
+ | `HTTP transport admission is closed` | A call after `close`, or one forced teardown ended after its own setup saw `close`, with no `cause` |
439
+
440
+ A server `RST_STREAM` on a gRPC call maps as connectrpc-async does: codes 3
441
+ and 11 to `resource_exhausted`, 7 to `unavailable`, 8 to `canceled`, 12 to
442
+ `permission_denied` and anything else to `internal`. Deadlines and cancellation
443
+ raise core's `deadline_exceeded` and `canceled` errors first.
444
+
445
+ `close(grace: 5)` stops admission, lets in-flight calls finish within `grace`,
446
+ then aborts the rest and waits for every connection task. It returns true when
447
+ everything drained and false after forced teardown; repeated and concurrent
448
+ calls share the first call's grace and outcome. Callers waiting for the shared
449
+ HTTP/2 dial fail with `HTTP transport admission is closed`, and the dial ends.
450
+ A call admitted before `close` that is dialing its own connection (per-call
451
+ mode, HTTP/1.1, a dial after an HTTP/1.1 outcome, or a retry's own dial) is in
452
+ flight: it keeps dialing and runs within the grace, but its new connection is
453
+ never pooled for other calls. Lazy exchanges that have not dispatched and
454
+ pending retries fail with `HTTP transport admission is closed`. Forced teardown
455
+ fails each call it ends `unavailable` with `HTTP transport admission is closed`
456
+ if the call's own setup saw `close` first, and otherwise with
457
+ `HTTP transport failed: connection closed`. Which of the two a call gets is
458
+ not guaranteed, and it never gets another phrase. Teardown runs in the
459
+ background once started, so it completes even if the closing thread is interrupted or a
460
+ fiber scheduler stops the closing task (async's `Task#stop`). Every closer, a
461
+ concurrent one included, keeps waiting for the outcome and raises the
462
+ exception after teardown. On a non-blocking fiber under a fiber scheduler that
463
+ wait runs on a helper thread, so sibling tasks still run and their calls can
464
+ drain, and threads that sibling tasks start meanwhile keep their usual
465
+ interrupt handling (see [fiber schedulers](#fiber-schedulers)). Such a closer
466
+ stops waiting if it is killed (`Fiber#kill` or `Thread#kill`); teardown still
467
+ completes, and later closers wait for and return the published outcome.
468
+ Without a fiber scheduler, or on a blocking fiber, a closer defers
469
+ `Thread#kill` until `close` returns.
470
+
471
+ ## License
472
+
473
+ MIT. The extension links third-party Rust crates under their own licenses,
474
+ listed with their license texts in
475
+ [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md).