Inline single-callsite request serialization functions
@@ -122,27 +122,14 @@ impl HttpClient {
};
let request = if !self.request_config.assert_identity {
- self.try_into_http_request(request, session, config).await?
- } else {
- self.try_into_http_request_with_identity_assertion(request, session, config).await?
- };
-
- self.inner.send_request(request, config).await
- }
-
- async fn try_into_http_request<Request: OutgoingRequest>(
- &self,
- request: Request,
- session: Arc<RwLock<Option<Session>>>,
- config: RequestConfig,
- ) -> Result<http::Request<Bytes>, HttpError> {
let auth_scheme = Request::METADATA.authentication;
if !matches!(auth_scheme, AuthScheme::AccessToken | AuthScheme::None) {
return Err(HttpError::NotClientRequest);
}
let access_token;
- let send_access_token = if matches!(auth_scheme, AuthScheme::None) && !config.force_auth {
+ let send_access_token = if matches!(auth_scheme, AuthScheme::None) && !config.force_auth
+ {
// Small optimization: Don't take the session lock if we know the auth token
// isn't going to be used anyways.
SendAccessToken::None
@@ -160,24 +147,15 @@ impl HttpClient {
}
};
- let http_request = request
+ request
.try_into_http_request::<BytesMut>(
&self.homeserver.read().await.to_string(),
send_access_token,
// FIXME: Use versions reported by server
&[MatrixVersion::V1_0],
)?
- .map(|body| body.freeze());
-
- Ok(http_request)
- }
-
- async fn try_into_http_request_with_identity_assertion<Request: OutgoingRequest>(
- &self,
- request: Request,
- session: Arc<RwLock<Option<Session>>>,
- _: RequestConfig,
- ) -> Result<http::Request<Bytes>, HttpError> {
+ .map(|body| body.freeze())
+ } else {
let read_guard = session.read().await;
let access_token = if let Some(session) = read_guard.as_ref() {
SendAccessToken::Always(session.access_token.as_str())
@@ -191,7 +169,7 @@ impl HttpClient {
return Err(HttpError::UserIdRequired);
};
- let http_request = request
+ request
.try_into_http_request_with_user_id::<BytesMut>(
&self.homeserver.read().await.to_string(),
access_token,
@@ -199,9 +177,10 @@ impl HttpClient {
// FIXME: Use versions reported by server
&[MatrixVersion::V1_0],
)?
- .map(|body| body.freeze());
+ .map(|body| body.freeze())
+ };
- Ok(http_request)
+ self.inner.send_request(request, config).await
}
pub async fn upload(
