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