matrix-sdk: Don't set the content type ourselves

We don't need to worry about this anymore, since Ruma sets this for all
the request nowadays.
master
Damir Jelić 2021-03-01 19:29:04 +01:00
parent 4c3cd29224
commit 3a08f0c278
1 changed files with 4 additions and 14 deletions

View File

@ -18,7 +18,7 @@ use std::{convert::TryFrom, fmt::Debug, sync::Arc};
use backoff::{future::retry, Error as RetryError, ExponentialBackoff}; use backoff::{future::retry, Error as RetryError, ExponentialBackoff};
#[cfg(all(not(test), not(target_arch = "wasm32")))] #[cfg(all(not(test), not(target_arch = "wasm32")))]
use http::StatusCode; use http::StatusCode;
use http::{HeaderValue, Method as HttpMethod, Response as HttpResponse}; use http::{HeaderValue, Response as HttpResponse};
use reqwest::{Client, Response}; use reqwest::{Client, Response};
use tracing::trace; use tracing::trace;
use url::Url; use url::Url;
@ -104,10 +104,9 @@ impl HttpClient {
&self, &self,
request: Request, request: Request,
session: Arc<RwLock<Option<Session>>>, session: Arc<RwLock<Option<Session>>>,
content_type: Option<HeaderValue>,
timeout: Option<Duration>, timeout: Option<Duration>,
) -> Result<http::Response<Vec<u8>>, HttpError> { ) -> Result<http::Response<Vec<u8>>, HttpError> {
let mut request = { let request = {
let read_guard; let read_guard;
let access_token = match Request::METADATA.authentication { let access_token = match Request::METADATA.authentication {
AuthScheme::AccessToken => { AuthScheme::AccessToken => {
@ -126,14 +125,6 @@ impl HttpClient {
request.try_into_http_request(&self.homeserver.to_string(), access_token)? request.try_into_http_request(&self.homeserver.to_string(), access_token)?
}; };
if let HttpMethod::POST | HttpMethod::PUT | HttpMethod::DELETE = *request.method() {
if let Some(content_type) = content_type {
request
.headers_mut()
.insert(http::header::CONTENT_TYPE, content_type);
}
}
self.inner.send_request(request, timeout).await self.inner.send_request(request, timeout).await
} }
@ -143,7 +134,7 @@ impl HttpClient {
timeout: Option<Duration>, timeout: Option<Duration>,
) -> Result<create_content::Response, HttpError> { ) -> Result<create_content::Response, HttpError> {
let response = self let response = self
.send_request(request, self.session.clone(), None, timeout) .send_request(request, self.session.clone(), timeout)
.await?; .await?;
Ok(create_content::Response::try_from(response)?) Ok(create_content::Response::try_from(response)?)
} }
@ -157,9 +148,8 @@ impl HttpClient {
Request: OutgoingRequest + Debug, Request: OutgoingRequest + Debug,
HttpError: From<FromHttpResponseError<Request::EndpointError>>, HttpError: From<FromHttpResponseError<Request::EndpointError>>,
{ {
let content_type = HeaderValue::from_static("application/json");
let response = self let response = self
.send_request(request, self.session.clone(), Some(content_type), timeout) .send_request(request, self.session.clone(), timeout)
.await?; .await?;
trace!("Got response: {:?}", response); trace!("Got response: {:?}", response);