Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Some minor fixes for some missed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich authored and stepancheg committed Jun 30, 2019
1 parent f8b029e commit f80ee0e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
9 changes: 6 additions & 3 deletions grpc-examples/greeter/src/bin/greeter_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ fn main() {
// TODO: simplify it
let mut tls_option =
httpbis::ClientTlsOption::Tls("foobar.com".to_owned(), Arc::new(test_tls_connector()));
let addr = SocketAddr::new("::1".parse().unwrap(), port);
let grpc_client =
Arc::new(grpc::Client::new_expl(&addr, "foobar.com", tls_option, client_conf).unwrap());
let grpc_client = Arc::new(
grpc::ClientBuilder::new("::1", port)
.explicit_tls(tls_option)
.build()
.unwrap(),
);
GreeterClient::with_client(grpc_client)
} else {
GreeterClient::new_plain("::1", port, client_conf).unwrap()
Expand Down
4 changes: 2 additions & 2 deletions grpc-examples/greeter/src/bin/greeter_client_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate futures;
extern crate grpc;
extern crate grpc_examples_greeter;

use grpc::Client;
use grpc::ClientBuilder;
use grpc::ClientStub;

use grpc_examples_greeter::helloworld::*;
Expand All @@ -17,7 +17,7 @@ fn main() {
.map(|s| s.to_owned())
.unwrap_or_else(|| "world".to_owned());

let client = Arc::new(Client::new_plain("::1", 50051, Default::default()).unwrap());
let client = Arc::new(ClientBuilder::new("::1", 50051).build().unwrap());
let greeter_client = GreeterClient::with_client(client.clone());
let greeter_client2 = GreeterClient::with_client(client);

Expand Down
40 changes: 31 additions & 9 deletions grpc/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ pub(crate) mod http_response_to_grpc_frames_typed;
pub(crate) mod req_sink;
pub(crate) mod types;

use std::net::SocketAddr;

use bytes::Bytes;
use tokio_core::reactor::Remote;

use httpbis;
use httpbis::ClientTlsOption;
use httpbis::Header;
use httpbis::Headers;
use httpbis::HttpScheme;
Expand All @@ -18,7 +17,6 @@ use tls_api;

use method::MethodDescriptor;

use error::*;
use result;

use client::http_request_to_grpc_frames_typed::http_req_to_grpc_frames_typed;
Expand All @@ -31,7 +29,6 @@ use or_static::arc::ArcOrStatic;
use proto::grpc_frame::write_grpc_frame_to_vec;
use req::*;
use resp::*;
use std::marker::PhantomData;

#[derive(Default, Debug, Clone)]
pub struct ClientConf {
Expand All @@ -49,12 +46,18 @@ enum ClientBuilderType<'a> {
Unix { socket: &'a str },
}

pub struct ClientBuilder<'a, T> {
enum Tls<T: tls_api::TlsConnector> {
Explict(ClientTlsOption<T>),
Implicit,
None,
}

pub struct ClientBuilder<'a, T: tls_api::TlsConnector> {
client_type: ClientBuilderType<'a>,
http_scheme: HttpScheme,
event_loop: Option<Remote>,
pub conf: ClientConf,
tls: PhantomData<T>,
tls: Tls<T>,
}

impl<'a, T: tls_api::TlsConnector> ClientBuilder<'a, T> {
Expand Down Expand Up @@ -91,6 +94,12 @@ impl<'a, T: tls_api::TlsConnector> ClientBuilder<'a, T> {
};
builder.event_loop = self.event_loop;
builder.conf = conf.http;
match self.tls {
Tls::Explict(tls) => {
builder.tls = tls;
}
Tls::Implicit | Tls::None => {}
}

Ok(Client {
client: ::std::sync::Arc::new(builder.build()?),
Expand All @@ -108,7 +117,7 @@ impl<'a> ClientBuilder<'a, tls_api_stub::TlsConnector> {
http_scheme: HttpScheme::Http,
event_loop: None,
conf: Default::default(),
tls: PhantomData,
tls: Tls::None,
}
}

Expand All @@ -118,7 +127,7 @@ impl<'a> ClientBuilder<'a, tls_api_stub::TlsConnector> {
http_scheme: HttpScheme::Http,
event_loop: None,
conf: Default::default(),
tls: PhantomData,
tls: Tls::None,
}
}

Expand All @@ -128,7 +137,20 @@ impl<'a> ClientBuilder<'a, tls_api_stub::TlsConnector> {
http_scheme: HttpScheme::Https,
event_loop: self.event_loop,
conf: self.conf,
tls: PhantomData,
tls: Tls::Implicit,
}
}

pub fn explicit_tls<TLS: tls_api::TlsConnector>(
self,
tls: ClientTlsOption<TLS>,
) -> ClientBuilder<'a, TLS> {
ClientBuilder {
client_type: self.client_type,
http_scheme: tls.http_scheme(),
event_loop: self.event_loop,
conf: self.conf,
tls: Tls::Explict(tls),
}
}
}
Expand Down

0 comments on commit f80ee0e

Please sign in to comment.