From 4c3cd292242209e7dd838919f36848dd39288bc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 1 Mar 2021 16:37:56 +0100 Subject: [PATCH 1/2] matrix-sdk: Don't set two content-type headers for json contents Ruma will for some requests already set the content-type for us to application/json, but for some it still seems to miss the header, since the headers are kept in a map add the header only if it isn't already there. --- matrix_sdk/src/http_client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix_sdk/src/http_client.rs b/matrix_sdk/src/http_client.rs index cd7d6265..2e508d69 100644 --- a/matrix_sdk/src/http_client.rs +++ b/matrix_sdk/src/http_client.rs @@ -130,7 +130,7 @@ impl HttpClient { if let Some(content_type) = content_type { request .headers_mut() - .append(http::header::CONTENT_TYPE, content_type); + .insert(http::header::CONTENT_TYPE, content_type); } } From 3a08f0c278a69b469d4a7a3b967871b2f7990452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 1 Mar 2021 19:29:04 +0100 Subject: [PATCH 2/2] 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. --- matrix_sdk/src/http_client.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/matrix_sdk/src/http_client.rs b/matrix_sdk/src/http_client.rs index 2e508d69..3e1cb8f2 100644 --- a/matrix_sdk/src/http_client.rs +++ b/matrix_sdk/src/http_client.rs @@ -18,7 +18,7 @@ use std::{convert::TryFrom, fmt::Debug, sync::Arc}; use backoff::{future::retry, Error as RetryError, ExponentialBackoff}; #[cfg(all(not(test), not(target_arch = "wasm32")))] use http::StatusCode; -use http::{HeaderValue, Method as HttpMethod, Response as HttpResponse}; +use http::{HeaderValue, Response as HttpResponse}; use reqwest::{Client, Response}; use tracing::trace; use url::Url; @@ -104,10 +104,9 @@ impl HttpClient { &self, request: Request, session: Arc>>, - content_type: Option, timeout: Option, ) -> Result>, HttpError> { - let mut request = { + let request = { let read_guard; let access_token = match Request::METADATA.authentication { AuthScheme::AccessToken => { @@ -126,14 +125,6 @@ impl HttpClient { 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 } @@ -143,7 +134,7 @@ impl HttpClient { timeout: Option, ) -> Result { let response = self - .send_request(request, self.session.clone(), None, timeout) + .send_request(request, self.session.clone(), timeout) .await?; Ok(create_content::Response::try_from(response)?) } @@ -157,9 +148,8 @@ impl HttpClient { Request: OutgoingRequest + Debug, HttpError: From>, { - let content_type = HeaderValue::from_static("application/json"); let response = self - .send_request(request, self.session.clone(), Some(content_type), timeout) + .send_request(request, self.session.clone(), timeout) .await?; trace!("Got response: {:?}", response);