wreq-rb 0.5.0 → 0.5.1
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 +4 -4
- data/Cargo.lock +1922 -397
- data/LICENSE +203 -0
- data/README.md +19 -15
- data/ext/wreq_rb/Cargo.toml +4 -6
- data/ext/wreq_rb/src/client.rs +41 -48
- data/lib/wreq-rb/version.rb +1 -1
- data/patches/0001-add-transfer-size-tracking.patch +76 -67
- data/vendor/wreq/Cargo.toml +119 -71
- data/vendor/wreq/README.md +25 -20
- data/vendor/wreq/bench/http1.rs +25 -0
- data/vendor/wreq/bench/http1_over_tls.rs +25 -0
- data/vendor/wreq/bench/http2.rs +25 -0
- data/vendor/wreq/bench/http2_over_tls.rs +25 -0
- data/vendor/wreq/bench/support/bench.rs +91 -0
- data/vendor/wreq/bench/support/client.rs +217 -0
- data/vendor/wreq/bench/support/server.rs +188 -0
- data/vendor/wreq/bench/support.rs +56 -0
- data/vendor/wreq/examples/cert_store.rs +4 -4
- data/vendor/wreq/examples/{emulation.rs → emulate.rs} +2 -2
- data/vendor/wreq/examples/http2_websocket.rs +2 -2
- data/vendor/wreq/examples/keylog.rs +3 -3
- data/vendor/wreq/examples/{request_with_emulation.rs → request_with_emulate.rs} +2 -2
- data/vendor/wreq/examples/rt.rs +23 -0
- data/vendor/wreq/src/client/body.rs +23 -61
- data/vendor/wreq/src/client/emulate.rs +119 -0
- data/vendor/wreq/src/client/{http/future.rs → future.rs} +11 -32
- data/vendor/wreq/src/client/{http → layer}/client/pool.rs +66 -61
- data/vendor/wreq/src/client/{http → layer}/client.rs +416 -270
- data/vendor/wreq/src/client/layer/config.rs +27 -6
- data/vendor/wreq/src/client/layer/decoder.rs +9 -4
- data/vendor/wreq/src/client/layer/redirect/future.rs +6 -3
- data/vendor/wreq/src/client/layer/redirect.rs +4 -5
- data/vendor/wreq/src/client/layer/retry.rs +8 -5
- data/vendor/wreq/src/client/layer/timeout/body.rs +15 -6
- data/vendor/wreq/src/client/layer/timeout/future.rs +23 -18
- data/vendor/wreq/src/client/layer/timeout.rs +24 -74
- data/vendor/wreq/src/client/layer.rs +1 -2
- data/vendor/wreq/src/client/multipart.rs +137 -154
- data/vendor/wreq/src/client/request.rs +202 -118
- data/vendor/wreq/src/client/response.rs +46 -45
- data/vendor/wreq/src/client/upgrade.rs +15 -0
- data/vendor/wreq/src/client/ws.rs +73 -25
- data/vendor/wreq/src/client.rs +1655 -17
- data/vendor/wreq/src/config.rs +11 -11
- data/vendor/wreq/src/{client/conn → conn}/connector.rs +139 -137
- data/vendor/wreq/src/conn/descriptor.rs +143 -0
- data/vendor/wreq/src/conn/http.rs +484 -0
- data/vendor/wreq/src/conn/net/io.rs +75 -0
- data/vendor/wreq/src/conn/net/tcp/compio.rs +71 -0
- data/vendor/wreq/src/conn/net/tcp/tokio.rs +57 -0
- data/vendor/wreq/src/conn/net/tcp.rs +561 -0
- data/vendor/wreq/src/conn/net/uds/compio.rs +60 -0
- data/vendor/wreq/src/{client/conn/uds.rs → conn/net/uds/tokio.rs} +18 -12
- data/vendor/wreq/src/conn/net/uds.rs +11 -0
- data/vendor/wreq/src/conn/net.rs +130 -0
- data/vendor/wreq/src/{client/conn → conn}/proxy/socks.rs +2 -9
- data/vendor/wreq/src/{client/conn → conn}/proxy/tunnel.rs +21 -56
- data/vendor/wreq/src/conn/tls_info.rs +47 -0
- data/vendor/wreq/src/{client/conn.rs → conn.rs} +202 -54
- data/vendor/wreq/src/cookie.rs +302 -142
- data/vendor/wreq/src/dns/gai/compio.rs +77 -0
- data/vendor/wreq/src/dns/gai/tokio.rs +90 -0
- data/vendor/wreq/src/dns/gai.rs +14 -164
- data/vendor/wreq/src/dns/hickory.rs +16 -23
- data/vendor/wreq/src/dns/resolve.rs +7 -41
- data/vendor/wreq/src/dns.rs +90 -7
- data/vendor/wreq/src/error.rs +57 -31
- data/vendor/wreq/src/ext.rs +25 -0
- data/vendor/wreq/src/group.rs +211 -0
- data/vendor/wreq/src/header.rs +100 -112
- data/vendor/wreq/src/lib.rs +124 -73
- data/vendor/wreq/src/proxy.rs +6 -20
- data/vendor/wreq/src/redirect.rs +1 -1
- data/vendor/wreq/src/rt.rs +208 -0
- data/vendor/wreq/src/sync.rs +97 -98
- data/vendor/wreq/src/tls/compress.rs +124 -0
- data/vendor/wreq/src/tls/conn/ext.rs +54 -45
- data/vendor/wreq/src/tls/conn/service.rs +14 -18
- data/vendor/wreq/src/tls/conn.rs +169 -241
- data/vendor/wreq/src/tls/keylog.rs +68 -5
- data/vendor/wreq/src/tls/session.rs +205 -0
- data/vendor/wreq/src/tls/{x509 → trust}/identity.rs +4 -21
- data/vendor/wreq/src/tls/{x509/parser.rs → trust/parse.rs} +1 -1
- data/vendor/wreq/src/tls/{x509 → trust}/store.rs +42 -81
- data/vendor/wreq/src/tls/{x509.rs → trust.rs} +8 -2
- data/vendor/wreq/src/tls.rs +489 -25
- data/vendor/wreq/src/trace.rs +0 -12
- data/vendor/wreq/src/util.rs +1 -1
- data/vendor/wreq/tests/badssl.rs +10 -10
- data/vendor/wreq/tests/client.rs +3 -9
- data/vendor/wreq/tests/cookie.rs +6 -8
- data/vendor/wreq/tests/{emulation.rs → emulate.rs} +130 -22
- data/vendor/wreq/tests/multipart.rs +43 -1
- data/vendor/wreq/tests/proxy.rs +1 -1
- data/vendor/wreq/tests/support/layer.rs +1 -0
- metadata +49 -71
- data/patches/0002-add-cancel-connections.patch +0 -181
- data/vendor/wreq/src/client/conn/conn.rs +0 -231
- data/vendor/wreq/src/client/conn/http.rs +0 -1023
- data/vendor/wreq/src/client/conn/tls_info.rs +0 -98
- data/vendor/wreq/src/client/core/body/incoming.rs +0 -485
- data/vendor/wreq/src/client/core/body/length.rs +0 -118
- data/vendor/wreq/src/client/core/body.rs +0 -34
- data/vendor/wreq/src/client/core/common/buf.rs +0 -149
- data/vendor/wreq/src/client/core/common/rewind.rs +0 -141
- data/vendor/wreq/src/client/core/common/watch.rs +0 -76
- data/vendor/wreq/src/client/core/common.rs +0 -3
- data/vendor/wreq/src/client/core/conn/http1.rs +0 -342
- data/vendor/wreq/src/client/core/conn/http2.rs +0 -307
- data/vendor/wreq/src/client/core/conn.rs +0 -11
- data/vendor/wreq/src/client/core/dispatch.rs +0 -299
- data/vendor/wreq/src/client/core/error.rs +0 -435
- data/vendor/wreq/src/client/core/ext.rs +0 -201
- data/vendor/wreq/src/client/core/http1.rs +0 -178
- data/vendor/wreq/src/client/core/http2.rs +0 -483
- data/vendor/wreq/src/client/core/proto/h1/conn.rs +0 -988
- data/vendor/wreq/src/client/core/proto/h1/decode.rs +0 -1170
- data/vendor/wreq/src/client/core/proto/h1/dispatch.rs +0 -684
- data/vendor/wreq/src/client/core/proto/h1/encode.rs +0 -580
- data/vendor/wreq/src/client/core/proto/h1/io.rs +0 -879
- data/vendor/wreq/src/client/core/proto/h1/role.rs +0 -694
- data/vendor/wreq/src/client/core/proto/h1.rs +0 -104
- data/vendor/wreq/src/client/core/proto/h2/client.rs +0 -650
- data/vendor/wreq/src/client/core/proto/h2/ping.rs +0 -539
- data/vendor/wreq/src/client/core/proto/h2.rs +0 -379
- data/vendor/wreq/src/client/core/proto/headers.rs +0 -138
- data/vendor/wreq/src/client/core/proto.rs +0 -58
- data/vendor/wreq/src/client/core/rt/bounds.rs +0 -57
- data/vendor/wreq/src/client/core/rt/timer.rs +0 -150
- data/vendor/wreq/src/client/core/rt/tokio.rs +0 -99
- data/vendor/wreq/src/client/core/rt.rs +0 -25
- data/vendor/wreq/src/client/core/upgrade.rs +0 -267
- data/vendor/wreq/src/client/core.rs +0 -16
- data/vendor/wreq/src/client/emulation.rs +0 -161
- data/vendor/wreq/src/client/http/client/error.rs +0 -142
- data/vendor/wreq/src/client/http/client/exec.rs +0 -29
- data/vendor/wreq/src/client/http/client/extra.rs +0 -77
- data/vendor/wreq/src/client/http/client/util.rs +0 -104
- data/vendor/wreq/src/client/http.rs +0 -1629
- data/vendor/wreq/src/client/layer/config/options.rs +0 -156
- data/vendor/wreq/src/client/layer/cookie.rs +0 -161
- data/vendor/wreq/src/hash.rs +0 -143
- data/vendor/wreq/src/tls/conn/cache.rs +0 -123
- data/vendor/wreq/src/tls/conn/cert_compression.rs +0 -125
- data/vendor/wreq/src/tls/keylog/handle.rs +0 -64
- data/vendor/wreq/src/tls/options.rs +0 -464
- /data/vendor/wreq/src/client/{http → layer}/client/lazy.rs +0 -0
- /data/vendor/wreq/src/{client/conn → conn}/proxy.rs +0 -0
- /data/vendor/wreq/src/{client/conn → conn}/verbose.rs +0 -0
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
diff --git a/src/client/http.rs b/src/client/http.rs
|
|
2
|
-
index 462c77d0..6231e700 100644
|
|
3
|
-
--- a/src/client/http.rs
|
|
4
|
-
+++ b/src/client/http.rs
|
|
5
|
-
@@ -171,6 +171,7 @@ type ClientRef = Either<ClientService, BoxedClientService>;
|
|
6
|
-
#[derive(Clone)]
|
|
7
|
-
pub struct Client {
|
|
8
|
-
inner: Arc<ClientRef>,
|
|
9
|
-
+ cancel_connections: Arc<dyn Fn() + Send + Sync>,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/// A [`ClientBuilder`] can be used to create a [`Client`] with custom configuration.
|
|
13
|
-
@@ -439,6 +440,14 @@ impl Client {
|
|
14
|
-
let fut = Oneshot::new(self.inner.as_ref().clone(), req);
|
|
15
|
-
Pending::request(uri, fut)
|
|
16
|
-
}
|
|
17
|
-
+
|
|
18
|
-
+ /// Cancel all background connection tasks immediately.
|
|
19
|
-
+ ///
|
|
20
|
-
+ /// This force-drops every tracked H1/H2 connection task, causing the
|
|
21
|
-
+ /// underlying TCP socket to close abruptly.
|
|
22
|
-
+ pub fn cancel_connections(&self) {
|
|
23
|
-
+ (self.cancel_connections)()
|
|
24
|
-
+ }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
impl tower::Service<Request> for Client {
|
|
28
|
-
@@ -495,7 +504,7 @@ impl ClientBuilder {
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Create base client service
|
|
32
|
-
- let service = {
|
|
33
|
-
+ let (service, cancel_connections) = {
|
|
34
|
-
let (tls_options, http1_options, http2_options) = config.transport_options.into();
|
|
35
|
-
|
|
36
|
-
let resolver = {
|
|
37
|
-
@@ -555,7 +564,7 @@ impl ClientBuilder {
|
|
38
|
-
.build(config.connector_layers)?;
|
|
39
|
-
|
|
40
|
-
// Build client
|
|
41
|
-
- HttpClient::builder(TokioExecutor::new())
|
|
42
|
-
+ let http_client = HttpClient::builder(TokioExecutor::new())
|
|
43
|
-
.http1_options(http1_options)
|
|
44
|
-
.http2_options(http2_options)
|
|
45
|
-
.http2_only(matches!(config.http_version_pref, HttpVersionPref::Http2))
|
|
46
|
-
@@ -564,8 +573,10 @@ impl ClientBuilder {
|
|
47
|
-
.pool_idle_timeout(config.pool_idle_timeout)
|
|
48
|
-
.pool_max_idle_per_host(config.pool_max_idle_per_host)
|
|
49
|
-
.pool_max_size(config.pool_max_size)
|
|
50
|
-
- .build(connector)
|
|
51
|
-
- .map_err(Into::into as _)
|
|
52
|
-
+ .build(connector);
|
|
53
|
-
+ // Capture abort fn before tower layers consume the client
|
|
54
|
-
+ let cancel_connections = http_client.cancel_connections_fn();
|
|
55
|
-
+ (http_client.map_err(Into::into as _), cancel_connections)
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Configured client service with layers
|
|
59
|
-
@@ -633,6 +644,7 @@ impl ClientBuilder {
|
|
60
|
-
|
|
61
|
-
Ok(Client {
|
|
62
|
-
inner: Arc::new(client),
|
|
63
|
-
+ cancel_connections,
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
diff --git a/src/client/http/client.rs b/src/client/http/client.rs
|
|
68
|
-
index a29c52dd..7f6ce68f 100644
|
|
69
|
-
--- a/src/client/http/client.rs
|
|
70
|
-
+++ b/src/client/http/client.rs
|
|
71
|
-
@@ -10,7 +10,7 @@ use std::{
|
|
72
|
-
future::Future,
|
|
73
|
-
num::NonZeroU32,
|
|
74
|
-
pin::Pin,
|
|
75
|
-
- sync::Arc,
|
|
76
|
-
+ sync::{Arc, Mutex},
|
|
77
|
-
task::{self, Poll},
|
|
78
|
-
time::Duration,
|
|
79
|
-
};
|
|
80
|
-
@@ -119,6 +119,7 @@ pub struct HttpClient<C, B> {
|
|
81
|
-
h1_builder: conn::http1::Builder,
|
|
82
|
-
h2_builder: conn::http2::Builder<Exec>,
|
|
83
|
-
pool: pool::Pool<PoolClient<B>, ConnectIdentity>,
|
|
84
|
-
+ conn_abort_handles: Arc<Mutex<Vec<tokio::task::AbortHandle>>>,
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
#[derive(Clone, Copy)]
|
|
88
|
-
@@ -452,8 +453,8 @@ where
|
|
89
|
-
+ Send
|
|
90
|
-
+ Unpin
|
|
91
|
-
+ 'static {
|
|
92
|
-
- let executor = self.exec.clone();
|
|
93
|
-
let pool = self.pool.clone();
|
|
94
|
-
+ let conn_abort_handles = self.conn_abort_handles.clone();
|
|
95
|
-
|
|
96
|
-
let h1_builder = self.h1_builder.clone();
|
|
97
|
-
let h2_builder = self.h2_builder.clone();
|
|
98
|
-
@@ -513,10 +514,17 @@ where
|
|
99
|
-
trace!(
|
|
100
|
-
"http2 handshake complete, spawning background dispatcher task"
|
|
101
|
-
);
|
|
102
|
-
- executor.execute(
|
|
103
|
-
- conn.map_err(|_e| debug!("client connection error: {}", _e))
|
|
104
|
-
- .map(|_| ()),
|
|
105
|
-
- );
|
|
106
|
-
+ let h2_conn_future = conn
|
|
107
|
-
+ .map_err(|_e| debug!("client connection error: {}", _e))
|
|
108
|
-
+ .map(|_| ());
|
|
109
|
-
+ let abort_handle = tokio::spawn(h2_conn_future).abort_handle();
|
|
110
|
-
+ {
|
|
111
|
-
+ let mut handles = conn_abort_handles.lock().unwrap_or_else(|e| e.into_inner());
|
|
112
|
-
+ if handles.len() >= 64 {
|
|
113
|
-
+ handles.retain(|h| !h.is_finished());
|
|
114
|
-
+ }
|
|
115
|
-
+ handles.push(abort_handle);
|
|
116
|
-
+ }
|
|
117
|
-
|
|
118
|
-
// Wait for 'conn' to ready up before we
|
|
119
|
-
// declare this tx as usable
|
|
120
|
-
@@ -544,8 +552,7 @@ where
|
|
121
|
-
// Spawn the connection task in the background using the executor.
|
|
122
|
-
// The task manages the HTTP/1.1 connection, including upgrades (e.g., WebSocket).
|
|
123
|
-
// Errors are sent via err_tx to ensure they can be checked if the sender (tx) fails.
|
|
124
|
-
- executor.execute(
|
|
125
|
-
- conn.with_upgrades()
|
|
126
|
-
+ let h1_conn_future = conn.with_upgrades()
|
|
127
|
-
.map_err(|e| {
|
|
128
|
-
// Log the connection error at debug level for diagnostic purposes.
|
|
129
|
-
debug!("client connection error: {:?}", e);
|
|
130
|
-
@@ -555,8 +562,15 @@ where
|
|
131
|
-
// (e.g., if the receiver is dropped, which is handled later).
|
|
132
|
-
let _ = err_tx.send(e);
|
|
133
|
-
})
|
|
134
|
-
- .map(|_| ()),
|
|
135
|
-
- );
|
|
136
|
-
+ .map(|_| ());
|
|
137
|
-
+ let abort_handle = tokio::spawn(h1_conn_future).abort_handle();
|
|
138
|
-
+ {
|
|
139
|
-
+ let mut handles = conn_abort_handles.lock().unwrap_or_else(|e| e.into_inner());
|
|
140
|
-
+ if handles.len() >= 64 {
|
|
141
|
-
+ handles.retain(|h| !h.is_finished());
|
|
142
|
-
+ }
|
|
143
|
-
+ handles.push(abort_handle);
|
|
144
|
-
+ }
|
|
145
|
-
|
|
146
|
-
// Log that the client is waiting for the connection to be ready.
|
|
147
|
-
// Readiness indicates the sender (tx) can accept a request without blocking. More actions
|
|
148
|
-
@@ -682,10 +696,25 @@ impl<C: Clone, B> Clone for HttpClient<C, B> {
|
|
149
|
-
h2_builder: self.h2_builder.clone(),
|
|
150
|
-
connector: self.connector.clone(),
|
|
151
|
-
pool: self.pool.clone(),
|
|
152
|
-
+ conn_abort_handles: self.conn_abort_handles.clone(),
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
+impl<C, B> HttpClient<C, B> {
|
|
158
|
-
+ /// Returns a closure that cancels all tracked connection tasks when called.
|
|
159
|
-
+ /// Each call drains the handle list and aborts every stored task.
|
|
160
|
-
+ pub fn cancel_connections_fn(&self) -> Arc<dyn Fn() + Send + Sync + 'static> {
|
|
161
|
-
+ let handles = self.conn_abort_handles.clone();
|
|
162
|
-
+ Arc::new(move || {
|
|
163
|
-
+ let mut guard = handles.lock().unwrap_or_else(|e| e.into_inner());
|
|
164
|
-
+ for handle in guard.drain(..) {
|
|
165
|
-
+ handle.abort();
|
|
166
|
-
+ }
|
|
167
|
-
+ })
|
|
168
|
-
+ }
|
|
169
|
-
+}
|
|
170
|
-
+
|
|
171
|
-
/// A pooled HTTP connection that can send requests
|
|
172
|
-
struct PoolClient<B> {
|
|
173
|
-
conn_info: Connected,
|
|
174
|
-
@@ -998,6 +1027,7 @@ impl Builder {
|
|
175
|
-
h2_builder: self.h2_builder,
|
|
176
|
-
connector,
|
|
177
|
-
pool: pool::Pool::new(self.pool_config, exec, timer),
|
|
178
|
-
+ conn_abort_handles: Arc::new(Mutex::new(Vec::new())),
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
use std::{
|
|
2
|
-
io::{self, IoSlice},
|
|
3
|
-
pin::Pin,
|
|
4
|
-
task::{Context, Poll},
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
use pin_project_lite::pin_project;
|
|
8
|
-
#[cfg(unix)]
|
|
9
|
-
use tokio::net::UnixStream;
|
|
10
|
-
use tokio::{
|
|
11
|
-
io::{AsyncRead, AsyncWrite, ReadBuf},
|
|
12
|
-
net::TcpStream,
|
|
13
|
-
};
|
|
14
|
-
use tokio_boring2::SslStream;
|
|
15
|
-
|
|
16
|
-
use super::{AsyncConnWithInfo, Connected, Connection, TlsInfoFactory};
|
|
17
|
-
use crate::{
|
|
18
|
-
proxy::matcher::Intercept,
|
|
19
|
-
tls::{TlsInfo, conn::MaybeHttpsStream},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
pin_project! {
|
|
23
|
-
/// Note: the `is_proxy` member means *is plain text HTTP proxy*.
|
|
24
|
-
/// This tells core whether the URI should be written in
|
|
25
|
-
/// * origin-form (`GET /just/a/path HTTP/1.1`), when `is_proxy == false`, or
|
|
26
|
-
/// * absolute-form (`GET http://foo.bar/and/a/path HTTP/1.1`), otherwise.
|
|
27
|
-
pub struct Conn {
|
|
28
|
-
#[pin]
|
|
29
|
-
pub(super) inner: Box<dyn AsyncConnWithInfo>,
|
|
30
|
-
pub(super) tls_info: bool,
|
|
31
|
-
pub(super) proxy: Option<Intercept>,
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
pin_project! {
|
|
36
|
-
/// A wrapper around `SslStream` that adapts it for use as a generic async connection.
|
|
37
|
-
///
|
|
38
|
-
/// This type enables unified handling of plain TCP and TLS-encrypted streams by providing
|
|
39
|
-
/// implementations of `Connection`, `Read`, `Write`, and `TlsInfoFactory`.
|
|
40
|
-
/// It is mainly used internally to abstract over different connection types.
|
|
41
|
-
pub struct TlsConn<T> {
|
|
42
|
-
#[pin]
|
|
43
|
-
inner: SslStream<T>,
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ==== impl Conn ====
|
|
48
|
-
|
|
49
|
-
impl Connection for Conn {
|
|
50
|
-
fn connected(&self) -> Connected {
|
|
51
|
-
let mut connected = self.inner.connected();
|
|
52
|
-
|
|
53
|
-
if let Some(proxy) = &self.proxy {
|
|
54
|
-
connected = connected.proxy(proxy.clone());
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if self.tls_info {
|
|
58
|
-
if let Some(tls_info) = self.inner.tls_info() {
|
|
59
|
-
connected.extra(tls_info)
|
|
60
|
-
} else {
|
|
61
|
-
connected
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
connected
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
impl AsyncRead for Conn {
|
|
70
|
-
#[inline]
|
|
71
|
-
fn poll_read(
|
|
72
|
-
self: Pin<&mut Self>,
|
|
73
|
-
cx: &mut Context,
|
|
74
|
-
buf: &mut ReadBuf<'_>,
|
|
75
|
-
) -> Poll<io::Result<()>> {
|
|
76
|
-
AsyncRead::poll_read(self.project().inner, cx, buf)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
impl AsyncWrite for Conn {
|
|
81
|
-
#[inline]
|
|
82
|
-
fn poll_write(
|
|
83
|
-
self: Pin<&mut Self>,
|
|
84
|
-
cx: &mut Context,
|
|
85
|
-
buf: &[u8],
|
|
86
|
-
) -> Poll<Result<usize, io::Error>> {
|
|
87
|
-
AsyncWrite::poll_write(self.project().inner, cx, buf)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
#[inline]
|
|
91
|
-
fn poll_write_vectored(
|
|
92
|
-
self: Pin<&mut Self>,
|
|
93
|
-
cx: &mut Context<'_>,
|
|
94
|
-
bufs: &[IoSlice<'_>],
|
|
95
|
-
) -> Poll<Result<usize, io::Error>> {
|
|
96
|
-
AsyncWrite::poll_write_vectored(self.project().inner, cx, bufs)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
#[inline]
|
|
100
|
-
fn is_write_vectored(&self) -> bool {
|
|
101
|
-
self.inner.is_write_vectored()
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
#[inline]
|
|
105
|
-
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), io::Error>> {
|
|
106
|
-
AsyncWrite::poll_flush(self.project().inner, cx)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
#[inline]
|
|
110
|
-
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), io::Error>> {
|
|
111
|
-
AsyncWrite::poll_shutdown(self.project().inner, cx)
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// ==== impl TlsConn ====
|
|
116
|
-
|
|
117
|
-
impl<T> TlsConn<T>
|
|
118
|
-
where
|
|
119
|
-
T: AsyncRead + AsyncWrite + Unpin,
|
|
120
|
-
{
|
|
121
|
-
/// Creates a new `TlsConn` wrapping the provided `SslStream`.
|
|
122
|
-
#[inline(always)]
|
|
123
|
-
pub fn new(inner: SslStream<T>) -> Self {
|
|
124
|
-
Self { inner }
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ===== impl TcpStream =====
|
|
129
|
-
|
|
130
|
-
impl Connection for TlsConn<TcpStream> {
|
|
131
|
-
fn connected(&self) -> Connected {
|
|
132
|
-
let connected = self.inner.get_ref().connected();
|
|
133
|
-
if self.inner.ssl().selected_alpn_protocol() == Some(b"h2") {
|
|
134
|
-
connected.negotiated_h2()
|
|
135
|
-
} else {
|
|
136
|
-
connected
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
impl Connection for TlsConn<MaybeHttpsStream<TcpStream>> {
|
|
142
|
-
fn connected(&self) -> Connected {
|
|
143
|
-
let connected = self.inner.get_ref().connected();
|
|
144
|
-
if self.inner.ssl().selected_alpn_protocol() == Some(b"h2") {
|
|
145
|
-
connected.negotiated_h2()
|
|
146
|
-
} else {
|
|
147
|
-
connected
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ===== impl UnixStream =====
|
|
153
|
-
|
|
154
|
-
#[cfg(unix)]
|
|
155
|
-
impl Connection for TlsConn<UnixStream> {
|
|
156
|
-
fn connected(&self) -> Connected {
|
|
157
|
-
let connected = self.inner.get_ref().connected();
|
|
158
|
-
if self.inner.ssl().selected_alpn_protocol() == Some(b"h2") {
|
|
159
|
-
connected.negotiated_h2()
|
|
160
|
-
} else {
|
|
161
|
-
connected
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
#[cfg(unix)]
|
|
167
|
-
impl Connection for TlsConn<MaybeHttpsStream<UnixStream>> {
|
|
168
|
-
fn connected(&self) -> Connected {
|
|
169
|
-
let connected = self.inner.get_ref().connected();
|
|
170
|
-
if self.inner.ssl().selected_alpn_protocol() == Some(b"h2") {
|
|
171
|
-
connected.negotiated_h2()
|
|
172
|
-
} else {
|
|
173
|
-
connected
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
impl<T: AsyncRead + AsyncWrite + Unpin> AsyncRead for TlsConn<T> {
|
|
179
|
-
#[inline]
|
|
180
|
-
fn poll_read(
|
|
181
|
-
self: Pin<&mut Self>,
|
|
182
|
-
cx: &mut Context,
|
|
183
|
-
buf: &mut ReadBuf<'_>,
|
|
184
|
-
) -> Poll<tokio::io::Result<()>> {
|
|
185
|
-
AsyncRead::poll_read(self.project().inner, cx, buf)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
impl<T: AsyncRead + AsyncWrite + Unpin> AsyncWrite for TlsConn<T> {
|
|
190
|
-
#[inline]
|
|
191
|
-
fn poll_write(
|
|
192
|
-
self: Pin<&mut Self>,
|
|
193
|
-
cx: &mut Context,
|
|
194
|
-
buf: &[u8],
|
|
195
|
-
) -> Poll<Result<usize, tokio::io::Error>> {
|
|
196
|
-
AsyncWrite::poll_write(self.project().inner, cx, buf)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
#[inline]
|
|
200
|
-
fn poll_write_vectored(
|
|
201
|
-
self: Pin<&mut Self>,
|
|
202
|
-
cx: &mut Context<'_>,
|
|
203
|
-
bufs: &[IoSlice<'_>],
|
|
204
|
-
) -> Poll<Result<usize, io::Error>> {
|
|
205
|
-
AsyncWrite::poll_write_vectored(self.project().inner, cx, bufs)
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
#[inline]
|
|
209
|
-
fn is_write_vectored(&self) -> bool {
|
|
210
|
-
self.inner.is_write_vectored()
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
#[inline]
|
|
214
|
-
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), tokio::io::Error>> {
|
|
215
|
-
AsyncWrite::poll_flush(self.project().inner, cx)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
#[inline]
|
|
219
|
-
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), tokio::io::Error>> {
|
|
220
|
-
AsyncWrite::poll_shutdown(self.project().inner, cx)
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
impl<T> TlsInfoFactory for TlsConn<T>
|
|
225
|
-
where
|
|
226
|
-
SslStream<T>: TlsInfoFactory,
|
|
227
|
-
{
|
|
228
|
-
fn tls_info(&self) -> Option<TlsInfo> {
|
|
229
|
-
self.inner.tls_info()
|
|
230
|
-
}
|
|
231
|
-
}
|