proxmox 0.10: use tokio::time::timeout directly

TimeoutFutureExt is no more

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-01-11 11:24:52 +01:00
parent 0a8d773ad0
commit d148958b67

View File

@ -18,7 +18,6 @@ use proxmox::{
api::error::HttpError, api::error::HttpError,
sys::linux::tty, sys::linux::tty,
tools::fs::{file_get_json, replace_file, CreateOptions}, tools::fs::{file_get_json, replace_file, CreateOptions},
tools::future::TimeoutFutureExt,
}; };
use super::pipe_to_stream::PipeToSendStream; use super::pipe_to_stream::PipeToSendStream;
@ -562,10 +561,12 @@ impl HttpClient {
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());
let resp = client let resp = tokio::time::timeout(
.request(req) HTTP_TIMEOUT,
.or_timeout_err(HTTP_TIMEOUT, format_err!("http download request timed out")) client.request(req)
.await?; )
.await
.map_err(|_| format_err!("http download request timed out"))??;
let status = resp.status(); let status = resp.status();
if !status.is_success() { if !status.is_success() {
HttpClient::api_response(resp) HttpClient::api_response(resp)
@ -632,10 +633,12 @@ impl HttpClient {
req.headers_mut().insert("UPGRADE", HeaderValue::from_str(&protocol_name).unwrap()); req.headers_mut().insert("UPGRADE", HeaderValue::from_str(&protocol_name).unwrap());
let resp = client let resp = tokio::time::timeout(
.request(req) HTTP_TIMEOUT,
.or_timeout_err(HTTP_TIMEOUT, format_err!("http upgrade request timed out")) client.request(req)
.await?; )
.await
.map_err(|_| format_err!("http upgrade request timed out"))??;
let status = resp.status(); let status = resp.status();
if status != http::StatusCode::SWITCHING_PROTOCOLS { if status != http::StatusCode::SWITCHING_PROTOCOLS {
@ -715,10 +718,14 @@ impl HttpClient {
req: Request<Body> req: Request<Body>
) -> Result<Value, Error> { ) -> Result<Value, Error> {
client.request(req) Self::api_response(
.or_timeout_err(HTTP_TIMEOUT, format_err!("http request timed out")) tokio::time::timeout(
.and_then(Self::api_response) HTTP_TIMEOUT,
.await client.request(req)
)
.await
.map_err(|_| format_err!("http request timed out"))??
).await
} }
// Read-only access to server property // Read-only access to server property