src/client/http_client.rs: split out code to start new h2 connections
This commit is contained in:
parent
b208da8393
commit
fb0470837b
@ -269,17 +269,26 @@ impl HttpClient {
|
|||||||
) -> impl Future<Item=BackupClient, Error=Error> {
|
) -> impl Future<Item=BackupClient, Error=Error> {
|
||||||
|
|
||||||
let param = json!({"backup-type": backup_type, "backup-id": backup_id, "store": datastore, "debug": debug});
|
let param = json!({"backup-type": backup_type, "backup-id": backup_id, "store": datastore, "debug": debug});
|
||||||
let mut req = Self::request_builder(&self.server, "GET", "/api2/json/backup", Some(param)).unwrap();
|
let req = Self::request_builder(&self.server, "GET", "/api2/json/backup", Some(param)).unwrap();
|
||||||
|
|
||||||
|
self.start_h2_connection(req, String::from(PROXMOX_BACKUP_PROTOCOL_ID_V1!()))
|
||||||
|
.map(|(h2, canceller)| BackupClient::new(h2, canceller))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start_h2_connection(
|
||||||
|
&self,
|
||||||
|
mut req: Request<Body>,
|
||||||
|
protocol_name: String,
|
||||||
|
) -> impl Future<Item=(H2Client, Canceller), Error=Error> {
|
||||||
|
|
||||||
let login = self.auth.listen();
|
let login = self.auth.listen();
|
||||||
|
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
|
|
||||||
login.and_then(move |auth| {
|
login.and_then(move |auth| {
|
||||||
|
|
||||||
let enc_ticket = format!("PBSAuthCookie={}", percent_encode(auth.ticket.as_bytes(), DEFAULT_ENCODE_SET));
|
let enc_ticket = format!("PBSAuthCookie={}", percent_encode(auth.ticket.as_bytes(), DEFAULT_ENCODE_SET));
|
||||||
req.headers_mut().insert("Cookie", HeaderValue::from_str(&enc_ticket).unwrap());
|
req.headers_mut().insert("Cookie", HeaderValue::from_str(&enc_ticket).unwrap());
|
||||||
req.headers_mut().insert("UPGRADE", HeaderValue::from_str(PROXMOX_BACKUP_PROTOCOL_ID_V1!()).unwrap());
|
req.headers_mut().insert("UPGRADE", HeaderValue::from_str(&protocol_name).unwrap());
|
||||||
|
|
||||||
client.request(req)
|
client.request(req)
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
@ -310,7 +319,7 @@ impl HttpClient {
|
|||||||
|
|
||||||
// Wait until the `SendRequest` handle has available capacity.
|
// Wait until the `SendRequest` handle has available capacity.
|
||||||
Ok(h2.ready()
|
Ok(h2.ready()
|
||||||
.map(move |c| BackupClient::new(c, canceller))
|
.map(move |c| (H2Client::new(c), canceller))
|
||||||
.map_err(Error::from))
|
.map_err(Error::from))
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
@ -428,11 +437,8 @@ pub struct BackupClient {
|
|||||||
|
|
||||||
impl BackupClient {
|
impl BackupClient {
|
||||||
|
|
||||||
pub fn new(h2: h2::client::SendRequest<bytes::Bytes>, canceller: Canceller) -> Self {
|
pub fn new(h2: H2Client, canceller: Canceller) -> Self {
|
||||||
Self {
|
Self { h2, canceller: Some(canceller) }
|
||||||
h2: H2Client::new(h2),
|
|
||||||
canceller: Some(canceller),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, path: &str, param: Option<Value>) -> impl Future<Item=Value, Error=Error> {
|
pub fn get(&self, path: &str, param: Option<Value>) -> impl Future<Item=Value, Error=Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user