api: Slightly optimize OutgoingRequest implementations
This commit is contained in:
parent
f818b53ca1
commit
1e005f576e
@ -138,12 +138,12 @@ impl Request {
|
|||||||
#( #attrs )*
|
#( #attrs )*
|
||||||
req_headers.insert(
|
req_headers.insert(
|
||||||
#http::header::AUTHORIZATION,
|
#http::header::AUTHORIZATION,
|
||||||
#http::header::HeaderValue::from_str(&::std::format!(
|
::std::convert::TryFrom::<_>::try_from(::std::format!(
|
||||||
"Bearer {}",
|
"Bearer {}",
|
||||||
access_token
|
access_token
|
||||||
.get_required()
|
.get_required()
|
||||||
.ok_or(#ruma_api::error::IntoHttpError::NeedsAuthentication)?,
|
.ok_or(#ruma_api::error::IntoHttpError::NeedsAuthentication)?,
|
||||||
))?
|
))?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -152,8 +152,8 @@ impl Request {
|
|||||||
#( #attrs )*
|
#( #attrs )*
|
||||||
req_headers.insert(
|
req_headers.insert(
|
||||||
#http::header::AUTHORIZATION,
|
#http::header::AUTHORIZATION,
|
||||||
#http::header::HeaderValue::from_str(
|
::std::convert::TryFrom::<_>::try_from(
|
||||||
&::std::format!("Bearer {}", access_token)
|
::std::format!("Bearer {}", access_token),
|
||||||
)?
|
)?
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
) -> Result<http::Request<T>, ruma_api::error::IntoHttpError> {
|
) -> Result<http::Request<T>, ruma_api::error::IntoHttpError> {
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use http::header::{self, HeaderValue};
|
use http::header;
|
||||||
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
|
||||||
|
|
||||||
let mut url = format!(
|
let mut url = format!(
|
||||||
@ -94,12 +94,12 @@ impl<'a> ruma_api::OutgoingRequest for Request<'a> {
|
|||||||
.header(header::CONTENT_TYPE, "application/json")
|
.header(header::CONTENT_TYPE, "application/json")
|
||||||
.header(
|
.header(
|
||||||
header::AUTHORIZATION,
|
header::AUTHORIZATION,
|
||||||
HeaderValue::from_str(&format!(
|
format!(
|
||||||
"Bearer {}",
|
"Bearer {}",
|
||||||
access_token
|
access_token
|
||||||
.get_required()
|
.get_required()
|
||||||
.ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?,
|
.ok_or(ruma_api::error::IntoHttpError::NeedsAuthentication)?,
|
||||||
))?,
|
),
|
||||||
)
|
)
|
||||||
.body(T::default())
|
.body(T::default())
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user