connectrpc-hyper 0.3.0
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/Cargo.lock +927 -0
- data/Cargo.toml +8 -0
- data/LICENSE +21 -0
- data/README.md +475 -0
- data/THIRD_PARTY_NOTICES.md +3886 -0
- data/ext/connectrpc_hyper/Cargo.toml +31 -0
- data/ext/connectrpc_hyper/extconf.rb +9 -0
- data/ext/connectrpc_hyper/src/body.rs +142 -0
- data/ext/connectrpc_hyper/src/call.rs +659 -0
- data/ext/connectrpc_hyper/src/conn.rs +825 -0
- data/ext/connectrpc_hyper/src/failure.rs +247 -0
- data/ext/connectrpc_hyper/src/gvl.rs +414 -0
- data/ext/connectrpc_hyper/src/holds.rs +241 -0
- data/ext/connectrpc_hyper/src/lib.rs +652 -0
- data/ext/connectrpc_hyper/src/pool.rs +1206 -0
- data/ext/connectrpc_hyper/src/runtime.rs +352 -0
- data/ext/connectrpc_hyper/src/tls.rs +114 -0
- data/ext/connectrpc_hyper/src/unary.rs +120 -0
- data/ext/connectrpc_hyper/src/wire.rs +513 -0
- data/lib/connectrpc/hyper/errors.rb +79 -0
- data/lib/connectrpc/hyper/exchange.rb +89 -0
- data/lib/connectrpc/hyper/tls.rb +110 -0
- data/lib/connectrpc/hyper/transport.rb +369 -0
- data/lib/connectrpc/hyper/version.rb +7 -0
- data/lib/connectrpc/hyper.rb +27 -0
- data/sig/connectrpc-hyper.rbs +23 -0
- data/sig/manifest.yaml +3 -0
- metadata +107 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "connectrpc_hyper"
|
|
3
|
+
version = "0.0.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
rust-version = "1.85"
|
|
6
|
+
publish = false
|
|
7
|
+
license = "MIT"
|
|
8
|
+
description = "Native hyper/h2/rustls client transport for the connectrpc-hyper gem"
|
|
9
|
+
|
|
10
|
+
[lib]
|
|
11
|
+
crate-type = ["cdylib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
bytes = "1.12.1"
|
|
15
|
+
h2 = "0.4.20"
|
|
16
|
+
http = "1.5.0"
|
|
17
|
+
http-body = "1.1.0"
|
|
18
|
+
http-body-util = "0.1.5"
|
|
19
|
+
hyper = { version = "1.13.0", features = ["client", "http1", "http2"] }
|
|
20
|
+
# Only the tokio runtime glue: no client-proxy feature, so nothing reads proxy
|
|
21
|
+
# environment variables.
|
|
22
|
+
hyper-util = { version = "0.1.21", default-features = false, features = ["tokio"] }
|
|
23
|
+
magnus = { version = "0.9.3", features = ["rb-sys"] }
|
|
24
|
+
rb-sys = "0.9.130"
|
|
25
|
+
rustls = { version = "0.23.46", default-features = false, features = ["aws_lc_rs", "prefer-post-quantum", "std", "tls12"] }
|
|
26
|
+
rustls-native-certs = "0.8.5"
|
|
27
|
+
tokio = { version = "1.54.1", features = ["rt", "rt-multi-thread", "net", "time", "sync", "macros", "io-util"] }
|
|
28
|
+
tokio-rustls = { version = "0.26.6", default-features = false, features = ["aws_lc_rs", "tls12"] }
|
|
29
|
+
|
|
30
|
+
[target.'cfg(unix)'.dependencies]
|
|
31
|
+
libc = "0.2.191"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "mkmf"
|
|
4
|
+
require "rb_sys/mkmf"
|
|
5
|
+
|
|
6
|
+
create_rust_makefile("connectrpc/hyper/connectrpc_hyper") do |extension|
|
|
7
|
+
# Cargo.lock is part of the package; a source install builds exactly it.
|
|
8
|
+
extension.extra_cargo_args += ["--locked"]
|
|
9
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
//! Request bodies: nothing, a fixed buffer, or an incrementally written
|
|
2
|
+
//! stream. An aborted stream fails with CANCEL instead of ending, so an
|
|
3
|
+
//! interrupted upload reaches the peer as RST_STREAM(CANCEL) (HTTP/2) or a
|
|
4
|
+
//! broken connection (HTTP/1.1), never as a clean end of the request.
|
|
5
|
+
use std::future::Future;
|
|
6
|
+
use std::pin::Pin;
|
|
7
|
+
use std::sync::Arc;
|
|
8
|
+
use std::sync::atomic::{AtomicBool, Ordering};
|
|
9
|
+
use std::task::{Context, Poll};
|
|
10
|
+
|
|
11
|
+
use bytes::Bytes;
|
|
12
|
+
use http_body::{Body, Frame, SizeHint};
|
|
13
|
+
use tokio::sync::{mpsc, oneshot};
|
|
14
|
+
|
|
15
|
+
use crate::gvl::Signal;
|
|
16
|
+
use crate::wire::Mark;
|
|
17
|
+
|
|
18
|
+
type AbortWait = Pin<Box<dyn Future<Output = ()> + Send + Sync>>;
|
|
19
|
+
|
|
20
|
+
pub struct CallBody {
|
|
21
|
+
kind: Kind,
|
|
22
|
+
/// The request's place in its HTTP/2 connection's stream order.
|
|
23
|
+
mark: Option<Arc<Mark>>,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
enum Kind {
|
|
27
|
+
Empty,
|
|
28
|
+
Full(Option<Bytes>),
|
|
29
|
+
Stream {
|
|
30
|
+
rx: Option<mpsc::Receiver<Bytes>>,
|
|
31
|
+
/// Set once the body ended cleanly (the writer closed its side).
|
|
32
|
+
ended: Arc<AtomicBool>,
|
|
33
|
+
abort: AbortWait,
|
|
34
|
+
/// Takes the receiver back when hyper drops a body that never
|
|
35
|
+
/// yielded a frame, so a replay can carry the writer's bytes.
|
|
36
|
+
home: Option<oneshot::Sender<mpsc::Receiver<Bytes>>>,
|
|
37
|
+
yielded: bool,
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl CallBody {
|
|
42
|
+
pub fn empty() -> Self {
|
|
43
|
+
Self::from(Kind::Empty)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
pub fn full(bytes: Bytes) -> Self {
|
|
47
|
+
Self::from(Kind::Full(Some(bytes)))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub fn stream(
|
|
51
|
+
rx: mpsc::Receiver<Bytes>,
|
|
52
|
+
ended: Arc<AtomicBool>,
|
|
53
|
+
abort: Arc<Signal>,
|
|
54
|
+
home: oneshot::Sender<mpsc::Receiver<Bytes>>,
|
|
55
|
+
) -> Self {
|
|
56
|
+
Self::from(Kind::Stream {
|
|
57
|
+
rx: Some(rx),
|
|
58
|
+
ended,
|
|
59
|
+
abort: Box::pin(async move { abort.wait().await }),
|
|
60
|
+
home: Some(home),
|
|
61
|
+
yielded: false,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fn from(kind: Kind) -> Self {
|
|
66
|
+
Self { kind, mark: None }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub fn set_mark(&mut self, mark: Option<Arc<Mark>>) {
|
|
70
|
+
self.mark = mark;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
impl Drop for CallBody {
|
|
75
|
+
fn drop(&mut self) {
|
|
76
|
+
if let Kind::Stream {
|
|
77
|
+
rx, home, yielded, ..
|
|
78
|
+
} = &mut self.kind
|
|
79
|
+
{
|
|
80
|
+
if let (false, Some(rx), Some(home)) = (*yielded, rx.take(), home.take()) {
|
|
81
|
+
// Nobody waiting closes the channel, as dropping it would.
|
|
82
|
+
let _ = home.send(rx);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
impl Body for CallBody {
|
|
89
|
+
type Data = Bytes;
|
|
90
|
+
type Error = h2::Error;
|
|
91
|
+
|
|
92
|
+
fn poll_frame(
|
|
93
|
+
self: Pin<&mut Self>,
|
|
94
|
+
cx: &mut Context<'_>,
|
|
95
|
+
) -> Poll<Option<Result<Frame<Bytes>, h2::Error>>> {
|
|
96
|
+
match &mut self.get_mut().kind {
|
|
97
|
+
Kind::Empty => Poll::Ready(None),
|
|
98
|
+
Kind::Full(data) => Poll::Ready(data.take().map(|bytes| Ok(Frame::data(bytes)))),
|
|
99
|
+
Kind::Stream {
|
|
100
|
+
rx,
|
|
101
|
+
ended,
|
|
102
|
+
abort,
|
|
103
|
+
yielded,
|
|
104
|
+
..
|
|
105
|
+
} => {
|
|
106
|
+
// Abort wins over queued bytes and over the writer's close.
|
|
107
|
+
if abort.as_mut().poll(cx).is_ready() {
|
|
108
|
+
*yielded = true;
|
|
109
|
+
return Poll::Ready(Some(Err(h2::Error::from(h2::Reason::CANCEL))));
|
|
110
|
+
}
|
|
111
|
+
let rx = rx.as_mut().expect("receiver until drop");
|
|
112
|
+
let polled = match rx.poll_recv(cx) {
|
|
113
|
+
Poll::Ready(Some(bytes)) => Poll::Ready(Some(Ok(Frame::data(bytes)))),
|
|
114
|
+
Poll::Ready(None) => {
|
|
115
|
+
ended.store(true, Ordering::SeqCst);
|
|
116
|
+
Poll::Ready(None)
|
|
117
|
+
}
|
|
118
|
+
Poll::Pending => return Poll::Pending,
|
|
119
|
+
};
|
|
120
|
+
*yielded = true;
|
|
121
|
+
polled
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
fn is_end_stream(&self) -> bool {
|
|
127
|
+
matches!(self.kind, Kind::Empty | Kind::Full(None))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fn size_hint(&self) -> SizeHint {
|
|
131
|
+
// hyper's HTTP/2 dispatch calls this once per request, right before
|
|
132
|
+
// h2 assigns its stream id (see wire.rs).
|
|
133
|
+
if let Some(mark) = &self.mark {
|
|
134
|
+
mark.take_index();
|
|
135
|
+
}
|
|
136
|
+
match &self.kind {
|
|
137
|
+
Kind::Empty | Kind::Full(None) => SizeHint::with_exact(0),
|
|
138
|
+
Kind::Full(Some(bytes)) => SizeHint::with_exact(bytes.len() as u64),
|
|
139
|
+
Kind::Stream { .. } => SizeHint::default(),
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|