2 use std
::task
::{Context, Poll}
;
3 use std
::sync
::{Arc, Mutex}
;
9 use http
::header
::HeaderValue
;
10 use http
::{Request, Response}
;
12 use hyper
::client
::{Client, HttpConnector}
;
13 use openssl
::{ssl::{SslConnector, SslMethod}
, x509
::X509StoreContextRef
};
14 use serde_json
::{json, Value}
;
15 use percent_encoding
::percent_encode
;
16 use xdg
::BaseDirectories
;
21 fs
::{file_get_json, replace_file, CreateOptions}
,
25 use super::pipe_to_stream
::PipeToSendStream
;
26 use crate::tools
::async_io
::EitherStream
;
27 use crate::tools
::{self, BroadcastFuture, DEFAULT_ENCODE_SET}
;
36 pub struct HttpClientOptions
{
37 prefix
: Option
<String
>,
38 password
: Option
<String
>,
39 fingerprint
: Option
<String
>,
42 fingerprint_cache
: bool
,
46 impl HttpClientOptions
{
48 pub fn new() -> Self {
55 fingerprint_cache
: false,
60 pub fn prefix(mut self, prefix
: Option
<String
>) -> Self {
65 pub fn password(mut self, password
: Option
<String
>) -> Self {
66 self.password
= password
;
70 pub fn fingerprint(mut self, fingerprint
: Option
<String
>) -> Self {
71 self.fingerprint
= fingerprint
;
75 pub fn interactive(mut self, interactive
: bool
) -> Self {
76 self.interactive
= interactive
;
80 pub fn ticket_cache(mut self, ticket_cache
: bool
) -> Self {
81 self.ticket_cache
= ticket_cache
;
85 pub fn fingerprint_cache(mut self, fingerprint_cache
: bool
) -> Self {
86 self.fingerprint_cache
= fingerprint_cache
;
90 pub fn verify_cert(mut self, verify_cert
: bool
) -> Self {
91 self.verify_cert
= verify_cert
;
96 /// HTTP(S) API client
97 pub struct HttpClient
{
98 client
: Client
<HttpsConnector
>,
100 fingerprint
: Arc
<Mutex
<Option
<String
>>>,
101 auth
: BroadcastFuture
<AuthInfo
>,
102 _options
: HttpClientOptions
,
105 /// Delete stored ticket data (logout)
106 pub fn delete_ticket_info(prefix
: &str, server
: &str, username
: &str) -> Result
<(), Error
> {
108 let base
= BaseDirectories
::with_prefix(prefix
)?
;
110 // usually /run/user/<uid>/...
111 let path
= base
.place_runtime_file("tickets")?
;
113 let mode
= nix
::sys
::stat
::Mode
::from_bits_truncate(0o0600);
115 let mut data
= file_get_json(&path
, Some(json
!({}
)))?
;
117 if let Some(map
) = data
[server
].as_object_mut() {
118 map
.remove(username
);
121 replace_file(path
, data
.to_string().as_bytes(), CreateOptions
::new().perm(mode
))?
;
126 fn store_fingerprint(prefix
: &str, server
: &str, fingerprint
: &str) -> Result
<(), Error
> {
128 let base
= BaseDirectories
::with_prefix(prefix
)?
;
130 // usually ~/.config/<prefix>/fingerprints
131 let path
= base
.place_config_file("fingerprints")?
;
133 let raw
= match std
::fs
::read_to_string(&path
) {
136 if err
.kind() == std
::io
::ErrorKind
::NotFound
{
139 bail
!("unable to read fingerprints from {:?} - {}", path
, err
);
144 let mut result
= String
::new();
146 raw
.split('
\n'
).for_each(|line
| {
147 let items
: Vec
<String
> = line
.split_whitespace().map(String
::from
).collect();
148 if items
.len() == 2 {
149 if &items
[0] == server
{
150 // found, add later with new fingerprint
152 result
.push_str(line
);
158 result
.push_str(server
);
160 result
.push_str(fingerprint
);
163 replace_file(path
, result
.as_bytes(), CreateOptions
::new())?
;
168 fn load_fingerprint(prefix
: &str, server
: &str) -> Option
<String
> {
170 let base
= BaseDirectories
::with_prefix(prefix
).ok()?
;
172 // usually ~/.config/<prefix>/fingerprints
173 let path
= base
.place_config_file("fingerprints").ok()?
;
175 let raw
= std
::fs
::read_to_string(&path
).ok()?
;
177 for line
in raw
.split('
\n'
) {
178 let items
: Vec
<String
> = line
.split_whitespace().map(String
::from
).collect();
179 if items
.len() == 2 {
180 if &items
[0] == server
{
181 return Some(items
[1].clone());
189 fn store_ticket_info(prefix
: &str, server
: &str, username
: &str, ticket
: &str, token
: &str) -> Result
<(), Error
> {
191 let base
= BaseDirectories
::with_prefix(prefix
)?
;
193 // usually /run/user/<uid>/...
194 let path
= base
.place_runtime_file("tickets")?
;
196 let mode
= nix
::sys
::stat
::Mode
::from_bits_truncate(0o0600);
198 let mut data
= file_get_json(&path
, Some(json
!({}
)))?
;
200 let now
= Utc
::now().timestamp();
202 data
[server
][username
] = json
!({ "timestamp": now, "ticket": ticket, "token": token}
);
204 let mut new_data
= json
!({}
);
206 let ticket_lifetime
= tools
::ticket
::TICKET_LIFETIME
- 60;
208 let empty
= serde_json
::map
::Map
::new();
209 for (server
, info
) in data
.as_object().unwrap_or(&empty
) {
210 for (_user
, uinfo
) in info
.as_object().unwrap_or(&empty
) {
211 if let Some(timestamp
) = uinfo
["timestamp"].as_i64() {
212 let age
= now
- timestamp
;
213 if age
< ticket_lifetime
{
214 new_data
[server
][username
] = uinfo
.clone();
220 replace_file(path
, new_data
.to_string().as_bytes(), CreateOptions
::new().perm(mode
))?
;
225 fn load_ticket_info(prefix
: &str, server
: &str, username
: &str) -> Option
<(String
, String
)> {
226 let base
= BaseDirectories
::with_prefix(prefix
).ok()?
;
228 // usually /run/user/<uid>/...
229 let path
= base
.place_runtime_file("tickets").ok()?
;
230 let data
= file_get_json(&path
, None
).ok()?
;
231 let now
= Utc
::now().timestamp();
232 let ticket_lifetime
= tools
::ticket
::TICKET_LIFETIME
- 60;
233 let uinfo
= data
[server
][username
].as_object()?
;
234 let timestamp
= uinfo
["timestamp"].as_i64()?
;
235 let age
= now
- timestamp
;
237 if age
< ticket_lifetime
{
238 let ticket
= uinfo
["ticket"].as_str()?
;
239 let token
= uinfo
["token"].as_str()?
;
240 Some((ticket
.to_owned(), token
.to_owned()))
248 pub fn new(server
: &str, username
: &str, mut options
: HttpClientOptions
) -> Result
<Self, Error
> {
250 let verified_fingerprint
= Arc
::new(Mutex
::new(None
));
252 let mut fingerprint
= options
.fingerprint
.take();
254 if fingerprint
.is_some() {
255 // do not store fingerprints passed via options in cache
256 options
.fingerprint_cache
= false;
257 } else if options
.fingerprint_cache
&& options
.prefix
.is_some() {
258 fingerprint
= load_fingerprint(options
.prefix
.as_ref().unwrap(), server
);
261 let mut ssl_connector_builder
= SslConnector
::builder(SslMethod
::tls()).unwrap();
263 if options
.verify_cert
{
264 let server
= server
.to_string();
265 let verified_fingerprint
= verified_fingerprint
.clone();
266 let interactive
= options
.interactive
;
267 let fingerprint_cache
= options
.fingerprint_cache
;
268 let prefix
= options
.prefix
.clone();
269 ssl_connector_builder
.set_verify_callback(openssl
::ssl
::SslVerifyMode
::PEER
, move |valid
, ctx
| {
270 let (valid
, fingerprint
) = Self::verify_callback(valid
, ctx
, fingerprint
.clone(), interactive
);
272 if let Some(fingerprint
) = fingerprint
{
273 if fingerprint_cache
&& prefix
.is_some() {
274 if let Err(err
) = store_fingerprint(
275 prefix
.as_ref().unwrap(), &server
, &fingerprint
) {
276 eprintln
!("{}", err
);
279 *verified_fingerprint
.lock().unwrap() = Some(fingerprint
);
285 ssl_connector_builder
.set_verify(openssl
::ssl
::SslVerifyMode
::NONE
);
288 let mut httpc
= hyper
::client
::HttpConnector
::new();
289 httpc
.set_nodelay(true); // important for h2 download performance!
290 httpc
.set_recv_buffer_size(Some(1024*1024)); //important for h2 download performance!
291 httpc
.enforce_http(false); // we want https...
293 let https
= HttpsConnector
::with_connector(httpc
, ssl_connector_builder
.build());
295 let client
= Client
::builder()
296 //.http2_initial_stream_window_size( (1 << 31) - 2)
297 //.http2_initial_connection_window_size( (1 << 31) - 2)
298 .build
::<_
, Body
>(https
);
300 let password
= options
.password
.take();
301 let use_ticket_cache
= options
.ticket_cache
&& options
.prefix
.is_some();
303 let password
= if let Some(password
) = password
{
306 let mut ticket_info
= None
;
307 if use_ticket_cache
{
308 ticket_info
= load_ticket_info(options
.prefix
.as_ref().unwrap(), server
, username
);
310 if let Some((ticket
, _token
)) = ticket_info
{
313 Self::get_password(&username
, options
.interactive
)?
317 let login_future
= Self::credentials(
323 let server
= server
.to_string();
324 let prefix
= options
.prefix
.clone();
327 if use_ticket_cache
& &prefix
.is_some() {
328 let _
= store_ticket_info(prefix
.as_ref().unwrap(), &server
, &auth
.username
, &auth
.ticket
, &auth
.token
);
337 server
: String
::from(server
),
338 fingerprint
: verified_fingerprint
,
339 auth
: BroadcastFuture
::new(Box
::new(login_future
)),
346 /// Login is done on demand, so this is onyl required if you need
347 /// access to authentication data in 'AuthInfo'.
348 pub async
fn login(&self) -> Result
<AuthInfo
, Error
> {
349 self.auth
.listen().await
352 /// Returns the optional fingerprint passed to the new() constructor.
353 pub fn fingerprint(&self) -> Option
<String
> {
354 (*self.fingerprint
.lock().unwrap()).clone()
357 fn get_password(username
: &str, interactive
: bool
) -> Result
<String
, Error
> {
358 // If we're on a TTY, query the user for a password
359 if interactive
&& tty
::stdin_isatty() {
360 let msg
= format
!("Password for \"{}\": ", username
);
361 return Ok(String
::from_utf8(tty
::read_password(&msg
)?
)?
);
364 bail
!("no password input mechanism available");
369 &mut X509StoreContextRef
,
370 expected_fingerprint
: Option
<String
>,
372 ) -> (bool
, Option
<String
>) {
373 if valid { return (true, None); }
375 let cert
= match ctx
.current_cert() {
377 None
=> return (false, None
),
380 let depth
= ctx
.error_depth();
381 if depth
!= 0 { return (false, None); }
383 let fp
= match cert
.digest(openssl
::hash
::MessageDigest
::sha256()) {
385 Err(_
) => return (false, None
), // should not happen
387 let fp_string
= proxmox
::tools
::digest_to_hex(&fp
);
388 let fp_string
= fp_string
.as_bytes().chunks(2).map(|v
| std
::str::from_utf8(v
).unwrap())
389 .collect
::<Vec
<&str>>().join(":");
391 if let Some(expected_fingerprint
) = expected_fingerprint
{
392 if expected_fingerprint
.to_lowercase() == fp_string
{
393 return (true, Some(fp_string
));
395 return (false, None
);
399 // If we're on a TTY, query the user
400 if interactive
&& tty
::stdin_isatty() {
401 println
!("fingerprint: {}", fp_string
);
403 print
!("Want to trust? (y/n): ");
404 let _
= std
::io
::stdout().flush();
405 let mut buf
= [0u8; 1];
407 match std
::io
::stdin().read_exact(&mut buf
) {
409 if buf
[0] == b'y'
|| buf
[0] == b'Y'
{
410 return (true, Some(fp_string
));
411 } else if buf
[0] == b'n'
|| buf
[0] == b'N'
{
412 return (false, None
);
416 return (false, None
);
424 pub async
fn request(&self, mut req
: Request
<Body
>) -> Result
<Value
, Error
> {
426 let client
= self.client
.clone();
428 let auth
= self.login().await?
;
430 let enc_ticket
= format
!("PBSAuthCookie={}", percent_encode(auth
.ticket
.as_bytes(), DEFAULT_ENCODE_SET
));
431 req
.headers_mut().insert("Cookie", HeaderValue
::from_str(&enc_ticket
).unwrap());
432 req
.headers_mut().insert("CSRFPreventionToken", HeaderValue
::from_str(&auth
.token
).unwrap());
434 Self::api_request(client
, req
).await
441 ) -> Result
<Value
, Error
> {
442 let req
= Self::request_builder(&self.server
, "GET", path
, data
).unwrap();
443 self.request(req
).await
450 ) -> Result
<Value
, Error
> {
451 let req
= Self::request_builder(&self.server
, "DELETE", path
, data
).unwrap();
452 self.request(req
).await
459 ) -> Result
<Value
, Error
> {
460 let req
= Self::request_builder(&self.server
, "POST", path
, data
).unwrap();
461 self.request(req
).await
464 pub async
fn download(
467 output
: &mut (dyn Write
+ Send
),
468 ) -> Result
<(), Error
> {
469 let mut req
= Self::request_builder(&self.server
, "GET", path
, None
).unwrap();
471 let client
= self.client
.clone();
473 let auth
= self.login().await?
;
475 let enc_ticket
= format
!("PBSAuthCookie={}", percent_encode(auth
.ticket
.as_bytes(), DEFAULT_ENCODE_SET
));
476 req
.headers_mut().insert("Cookie", HeaderValue
::from_str(&enc_ticket
).unwrap());
478 let resp
= client
.request(req
).await?
;
479 let status
= resp
.status();
480 if !status
.is_success() {
481 HttpClient
::api_response(resp
)
482 .map(|_
| Err(format_err
!("unknown error")))
486 .map_err(Error
::from
)
487 .try_fold(output
, move |acc
, chunk
| async
move {
488 acc
.write_all(&chunk
)?
;
502 ) -> Result
<Value
, Error
> {
504 let path
= path
.trim_matches('
/'
);
505 let mut url
= format
!("https://{}:8007/{}", &self.server
, path
);
507 if let Some(data
) = data
{
508 let query
= tools
::json_object_to_query(data
).unwrap();
510 url
.push_str(&query
);
513 let url
: Uri
= url
.parse().unwrap();
515 let req
= Request
::builder()
518 .header("User-Agent", "proxmox-backup-client/1.0")
519 .header("Content-Type", content_type
)
520 .body(body
).unwrap();
522 self.request(req
).await
525 pub async
fn start_h2_connection(
527 mut req
: Request
<Body
>,
528 protocol_name
: String
,
529 ) -> Result
<(H2Client
, futures
::future
::AbortHandle
), Error
> {
531 let auth
= self.login().await?
;
532 let client
= self.client
.clone();
534 let enc_ticket
= format
!("PBSAuthCookie={}", percent_encode(auth
.ticket
.as_bytes(), DEFAULT_ENCODE_SET
));
535 req
.headers_mut().insert("Cookie", HeaderValue
::from_str(&enc_ticket
).unwrap());
536 req
.headers_mut().insert("UPGRADE", HeaderValue
::from_str(&protocol_name
).unwrap());
538 let resp
= client
.request(req
).await?
;
539 let status
= resp
.status();
541 if status
!= http
::StatusCode
::SWITCHING_PROTOCOLS
{
542 Self::api_response(resp
).await?
;
543 bail
!("unknown error");
551 let max_window_size
= (1 << 31) - 2;
553 let (h2
, connection
) = h2
::client
::Builder
::new()
554 .initial_connection_window_size(max_window_size
)
555 .initial_window_size(max_window_size
)
556 .max_frame_size(4*1024*1024)
560 let connection
= connection
561 .map_err(|_
| panic
!("HTTP/2.0 connection failed"));
563 let (connection
, abort
) = futures
::future
::abortable(connection
);
564 // A cancellable future returns an Option which is None when cancelled and
565 // Some when it finished instead, since we don't care about the return type we
566 // need to map it away:
567 let connection
= connection
.map(|_
| ());
569 // Spawn a new task to drive the connection state
570 tokio
::spawn(connection
);
572 // Wait until the `SendRequest` handle has available capacity.
573 let c
= h2
.ready().await?
;
574 Ok((H2Client
::new(c
), abort
))
577 async
fn credentials(
578 client
: Client
<HttpsConnector
>,
582 ) -> Result
<AuthInfo
, Error
> {
583 let data
= json
!({ "username": username, "password": password }
);
584 let req
= Self::request_builder(&server
, "POST", "/api2/json/access/ticket", Some(data
)).unwrap();
585 let cred
= Self::api_request(client
, req
).await?
;
586 let auth
= AuthInfo
{
587 username
: cred
["data"]["username"].as_str().unwrap().to_owned(),
588 ticket
: cred
["data"]["ticket"].as_str().unwrap().to_owned(),
589 token
: cred
["data"]["CSRFPreventionToken"].as_str().unwrap().to_owned(),
595 async
fn api_response(response
: Response
<Body
>) -> Result
<Value
, Error
> {
596 let status
= response
.status();
597 let data
= hyper
::body
::to_bytes(response
.into_body()).await?
;
599 let text
= String
::from_utf8(data
.to_vec()).unwrap();
600 if status
.is_success() {
604 let value
: Value
= serde_json
::from_str(&text
)?
;
608 bail
!("HTTP Error {}: {}", status
, text
);
612 async
fn api_request(
613 client
: Client
<HttpsConnector
>,
615 ) -> Result
<Value
, Error
> {
618 .map_err(Error
::from
)
619 .and_then(Self::api_response
)
623 // Read-only access to server property
624 pub fn server(&self) -> &str {
628 pub fn request_builder(server
: &str, method
: &str, path
: &str, data
: Option
<Value
>) -> Result
<Request
<Body
>, Error
> {
629 let path
= path
.trim_matches('
/'
);
630 let url
: Uri
= format
!("https://{}:8007/{}", server
, path
).parse()?
;
632 if let Some(data
) = data
{
633 if method
== "POST" {
634 let request
= Request
::builder()
637 .header("User-Agent", "proxmox-backup-client/1.0")
638 .header(hyper
::header
::CONTENT_TYPE
, "application/json")
639 .body(Body
::from(data
.to_string()))?
;
642 let query
= tools
::json_object_to_query(data
)?
;
643 let url
: Uri
= format
!("https://{}:8007/{}?{}", server
, path
, query
).parse()?
;
644 let request
= Request
::builder()
647 .header("User-Agent", "proxmox-backup-client/1.0")
648 .header(hyper
::header
::CONTENT_TYPE
, "application/x-www-form-urlencoded")
649 .body(Body
::empty())?
;
654 let request
= Request
::builder()
657 .header("User-Agent", "proxmox-backup-client/1.0")
658 .header(hyper
::header
::CONTENT_TYPE
, "application/x-www-form-urlencoded")
659 .body(Body
::empty())?
;
667 pub struct H2Client
{
668 h2
: h2
::client
::SendRequest
<bytes
::Bytes
>,
673 pub fn new(h2
: h2
::client
::SendRequest
<bytes
::Bytes
>) -> Self {
681 ) -> Result
<Value
, Error
> {
682 let req
= Self::request_builder("localhost", "GET", path
, param
, None
).unwrap();
683 self.request(req
).await
690 ) -> Result
<Value
, Error
> {
691 let req
= Self::request_builder("localhost", "PUT", path
, param
, None
).unwrap();
692 self.request(req
).await
699 ) -> Result
<Value
, Error
> {
700 let req
= Self::request_builder("localhost", "POST", path
, param
, None
).unwrap();
701 self.request(req
).await
704 pub async
fn download
<W
: Write
+ Send
>(
707 param
: Option
<Value
>,
709 ) -> Result
<W
, Error
> {
710 let request
= Self::request_builder("localhost", "GET", path
, param
, None
).unwrap();
712 let response_future
= self.send_request(request
, None
).await?
;
714 let resp
= response_future
.await?
;
716 let status
= resp
.status();
717 if !status
.is_success() {
718 H2Client
::h2api_response(resp
).await?
; // raise error
722 let mut body
= resp
.into_body();
723 while let Some(chunk
) = body
.data().await
{
725 body
.flow_control().release_capacity(chunk
.len())?
;
726 output
.write_all(&chunk
)?
;
734 method
: &str, // POST or PUT
736 param
: Option
<Value
>,
739 ) -> Result
<Value
, Error
> {
740 let request
= Self::request_builder("localhost", method
, path
, param
, Some(content_type
)).unwrap();
742 let mut send_request
= self.h2
.clone().ready().await?
;
744 let (response
, stream
) = send_request
.send_request(request
, false).unwrap();
746 PipeToSendStream
::new(bytes
::Bytes
::from(data
), stream
).await?
;
749 .map_err(Error
::from
)
750 .and_then(Self::h2api_response
)
756 request
: Request
<()>,
757 ) -> Result
<Value
, Error
> {
759 self.send_request(request
, None
)
760 .and_then(move |response
| {
762 .map_err(Error
::from
)
763 .and_then(Self::h2api_response
)
770 request
: Request
<()>,
771 data
: Option
<bytes
::Bytes
>,
772 ) -> impl Future
<Output
= Result
<h2
::client
::ResponseFuture
, Error
>> {
776 .map_err(Error
::from
)
777 .and_then(move |mut send_request
| async
move {
778 if let Some(data
) = data
{
779 let (response
, stream
) = send_request
.send_request(request
, false).unwrap();
780 PipeToSendStream
::new(data
, stream
).await?
;
783 let (response
, _stream
) = send_request
.send_request(request
, true).unwrap();
789 pub async
fn h2api_response(
790 response
: Response
<h2
::RecvStream
>,
791 ) -> Result
<Value
, Error
> {
792 let status
= response
.status();
794 let (_head
, mut body
) = response
.into_parts();
796 let mut data
= Vec
::new();
797 while let Some(chunk
) = body
.data().await
{
799 // Whenever data is received, the caller is responsible for
800 // releasing capacity back to the server once it has freed
801 // the data from memory.
802 // Let the server send more data.
803 body
.flow_control().release_capacity(chunk
.len())?
;
807 let text
= String
::from_utf8(data
.to_vec()).unwrap();
808 if status
.is_success() {
812 let mut value
: Value
= serde_json
::from_str(&text
)?
;
813 if let Some(map
) = value
.as_object_mut() {
814 if let Some(data
) = map
.remove("data") {
818 bail
!("got result without data property");
821 bail
!("HTTP Error {}: {}", status
, text
);
825 // Note: We always encode parameters with the url
826 pub fn request_builder(
830 param
: Option
<Value
>,
831 content_type
: Option
<&str>,
832 ) -> Result
<Request
<()>, Error
> {
833 let path
= path
.trim_matches('
/'
);
835 let content_type
= content_type
.unwrap_or("application/x-www-form-urlencoded");
837 if let Some(param
) = param
{
838 let query
= tools
::json_object_to_query(param
)?
;
839 // We detected problem with hyper around 6000 characters - seo we try to keep on the safe side
840 if query
.len() > 4096 { bail!("h2 query data too large ({} bytes
) - please encode data inside body
", query.len()); }
841 let url: Uri = format!("https
://{}:8007/{}?{}", server, path, query).parse()?;
842 let request
= Request
::builder()
845 .header("User-Agent", "proxmox-backup-client/1.0")
846 .header(hyper
::header
::CONTENT_TYPE
, content_type
)
850 let url
: Uri
= format
!("https://{}:8007/{}", server
, path
).parse()?
;
851 let request
= Request
::builder()
854 .header("User-Agent", "proxmox-backup-client/1.0")
855 .header(hyper
::header
::CONTENT_TYPE
, content_type
)
864 pub struct HttpsConnector
{
866 ssl_connector
: std
::sync
::Arc
<SslConnector
>,
869 impl HttpsConnector
{
870 pub fn with_connector(mut http
: HttpConnector
, ssl_connector
: SslConnector
) -> Self {
871 http
.enforce_http(false);
875 ssl_connector
: std
::sync
::Arc
::new(ssl_connector
),
880 type MaybeTlsStream
= EitherStream
<
881 tokio
::net
::TcpStream
,
882 tokio_openssl
::SslStream
<tokio
::net
::TcpStream
>,
885 impl hyper
::service
::Service
<Uri
> for HttpsConnector
{
886 type Response
= MaybeTlsStream
;
888 type Future
= std
::pin
::Pin
<Box
<
889 dyn Future
<Output
= Result
<Self::Response
, Self::Error
>> + Send
+ '
static
892 fn poll_ready(&mut self, _
: &mut Context
<'_
>) -> Poll
<Result
<(), Self::Error
>> {
893 // This connector is always ready, but others might not be.
897 fn call(&mut self, dst
: Uri
) -> Self::Future
{
898 let mut this
= self.clone();
902 .ok_or_else(|| format_err
!("missing URL scheme"))?
906 .ok_or_else(|| format_err
!("missing hostname in destination url?"))?
909 let config
= this
.ssl_connector
.configure();
910 let conn
= this
.http
.call(dst
).await?
;
912 let conn
= tokio_openssl
::connect(config?
, &host
, conn
).await?
;
913 Ok(MaybeTlsStream
::Right(conn
))
915 Ok(MaybeTlsStream
::Left(conn
))