Skip to content

Commit 87019df

Browse files
committed
Updates for grpc
1 parent 47e5d90 commit 87019df

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

httpbis/src/client/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use futures::future::TryFutureExt;
1212
use futures::stream::StreamExt;
1313
use tls_api::TlsConnector;
1414
use tls_api::TlsConnectorBuilder;
15+
use tls_api::TlsConnectorType;
1516
use tokio::runtime::Handle;
1617
use tokio::runtime::Runtime;
1718

@@ -108,21 +109,31 @@ impl ClientBuilder {
108109

109110
/// Configure using given TLS connector with default options
110111
/// (e.g. no custom server certificates).
111-
pub fn set_tls<C: tls_api::TlsConnector>(&mut self, host: &str) -> crate::Result<()> {
112-
let mut tls_connector = C::builder()?;
112+
pub fn set_tls_dyn(
113+
&mut self,
114+
host: &str,
115+
connector: &'static dyn TlsConnectorType,
116+
) -> crate::Result<()> {
117+
let mut tls_connector = connector.builder()?;
113118

114-
if C::SUPPORTS_ALPN {
119+
if connector.supports_alpn() {
115120
// TODO: check negotiated protocol after connect
116121
tls_connector.set_alpn_protocols(&[b"h2"])?;
117122
}
118123

119124
let tls_connector = tls_connector.build()?;
120125

121-
let tls_connector = Arc::new(tls_connector.into_dyn());
126+
let tls_connector = Arc::new(tls_connector);
122127
self.tls = ClientTlsOption::Tls(host.to_owned(), tls_connector);
123128
Ok(())
124129
}
125130

131+
/// Configure using given TLS connector with default options
132+
/// (e.g. no custom server certificates).
133+
pub fn set_tls<C: tls_api::TlsConnector>(&mut self, host: &str) -> crate::Result<()> {
134+
self.set_tls_dyn(host, C::TYPE_DYN)
135+
}
136+
126137
/// Finish the client construction.
127138
pub fn build(self) -> crate::Result<Client> {
128139
let client_died_error_holder = SomethingDiedErrorHolder::new();

httpbis/src/client/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl Clone for ClientTlsOption {
2323

2424
impl ClientTlsOption {
2525
/// HTTP scheme for the connector.
26-
pub(crate) fn http_scheme(&self) -> HttpScheme {
26+
pub fn http_scheme(&self) -> HttpScheme {
2727
match self {
2828
&ClientTlsOption::Plain => HttpScheme::Http,
2929
&ClientTlsOption::Tls(..) => HttpScheme::Https,

httpbis/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#[macro_use]
1212
extern crate log;
1313

14+
pub use bytes_ext::buf_get_bytes::BufGetBytes;
1415
pub use client::conf::ClientConf;
1516
pub use client::handler::ClientHandler;
1617
pub use client::intf::ClientIntf;
@@ -46,6 +47,8 @@ pub use solicit::header::Header;
4647
pub use solicit::header::Headers;
4748
pub use solicit::stream_id::StreamId;
4849
pub use solicit::HttpScheme;
50+
pub use solicit_async::TryFutureBox;
51+
pub use solicit_async::TryStreamBox;
4952

5053
mod ascii;
5154
mod assert_types;

httpbis/src/server/conn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ where
137137
let mut stream_handler = None;
138138
let invoke_result = {
139139
let req = ServerRequest {
140+
loop_handle: &self.loop_handle,
140141
headers,
141142
end_stream,
142143
stream_id,

httpbis/src/server/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rand::thread_rng;
1616
use rand::Rng;
1717
use tls_api;
1818
use tls_api::TlsAcceptor;
19+
use tls_api::TlsAcceptorBox;
1920
use tokio::runtime::Handle;
2021
use tokio::runtime::Runtime;
2122

@@ -130,7 +131,12 @@ impl ServerBuilder {
130131

131132
/// Set TLS acceptor for the server. If not called, server will be non-TLS.
132133
pub fn set_tls<A: TlsAcceptor>(&mut self, acceptor: A) {
133-
self.tls = ServerTlsOption::Tls(Arc::new(acceptor.into_dyn()));
134+
self.set_tls_dyn(acceptor.into_dyn())
135+
}
136+
137+
/// Set TLS acceptor for the server. If not called, server will be non-TLS.
138+
pub fn set_tls_dyn(&mut self, acceptor: TlsAcceptorBox) {
139+
self.tls = ServerTlsOption::Tls(Arc::new(acceptor));
134140
}
135141

136142
/// Construct a server.

httpbis/src/server/req.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ use crate::EndStream;
1515
use crate::Headers;
1616
use crate::StreamAfterHeaders;
1717
use crate::StreamId;
18+
use tokio::runtime::Handle;
1819

1920
/// A request object provided to the server callback.
2021
pub struct ServerRequest<'a> {
22+
pub(crate) loop_handle: &'a Handle,
2123
/// Request headers.
2224
pub headers: Headers,
2325
/// True if requests ends with headers (no body).
@@ -31,6 +33,11 @@ pub struct ServerRequest<'a> {
3133
}
3234

3335
impl<'a> ServerRequest<'a> {
36+
/// Get a loop handle.
37+
pub fn loop_handle(&self) -> Handle {
38+
self.loop_handle.clone()
39+
}
40+
3441
/// Convert a request into a pullable stream.
3542
pub fn into_stream(self) -> impl StreamAfterHeaders {
3643
match self.end_stream {

httpbis/src/solicit_async.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use crate::solicit::frame::FRAME_HEADER_LEN;
2424

2525
use crate::misc::BsDebug;
2626

27+
/// Type alias.
2728
pub type TryFutureBox<T> = Pin<Box<dyn Future<Output = crate::Result<T>> + Send + 'static>>;
29+
/// Type alias.
2830
pub type TryStreamBox<T> = Pin<Box<dyn Stream<Item = crate::Result<T>> + Send + 'static>>;
2931

3032
/// Inefficient, but OK because used only in tests

0 commit comments

Comments
 (0)