From 7df5a0f09d93342dcc296a27c069cc288e3f3e0d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 21 Sep 2021 18:54:10 +0200 Subject: [PATCH] api: Fix inverse condition for sending application/json content-type --- crates/ruma-api-macros/src/request/outgoing.rs | 4 ++-- crates/ruma-api/CHANGELOG.md | 6 ++++-- crates/ruma-client-api/tests/headers.rs | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 crates/ruma-client-api/tests/headers.rs diff --git a/crates/ruma-api-macros/src/request/outgoing.rs b/crates/ruma-api-macros/src/request/outgoing.rs index 3711e92d..a7da4e73 100644 --- a/crates/ruma-api-macros/src/request/outgoing.rs +++ b/crates/ruma-api-macros/src/request/outgoing.rs @@ -102,14 +102,14 @@ impl Request { // policies that don't allow the `Content-Type` header (for things such as `.well-known` // that are commonly handled by something else than a homeserver). let mut header_kvs = if self.raw_body_field().is_some() || self.has_body_fields() { - TokenStream::new() - } else { quote! { req_headers.insert( #http::header::CONTENT_TYPE, #http::header::HeaderValue::from_static("application/json"), ); } + } else { + TokenStream::new() }; header_kvs.extend(self.header_fields().map(|request_field| { diff --git a/crates/ruma-api/CHANGELOG.md b/crates/ruma-api/CHANGELOG.md index abd70ac5..10030c81 100644 --- a/crates/ruma-api/CHANGELOG.md +++ b/crates/ruma-api/CHANGELOG.md @@ -1,7 +1,5 @@ # [unreleased] -# 0.18.4 - Bug fixes: * Stop adding a `Content-Type` header to requests without any fields @@ -9,6 +7,10 @@ Bug fixes: environment if the server isn't configured to allow that header for cross-origin requests +# 0.18.4 + +Yanked. + # 0.18.3 Improvements: diff --git a/crates/ruma-client-api/tests/headers.rs b/crates/ruma-client-api/tests/headers.rs new file mode 100644 index 00000000..f9cd338c --- /dev/null +++ b/crates/ruma-client-api/tests/headers.rs @@ -0,0 +1,14 @@ +#![cfg(feature = "client")] + +use http::HeaderMap; +use ruma_api::{OutgoingRequest as _, SendAccessToken}; +use ruma_client_api::unversioned::discover_homeserver; + +#[test] +fn get_request_headers() { + let req: http::Request> = discover_homeserver::Request::new() + .try_into_http_request("https://homeserver.tld", SendAccessToken::None) + .unwrap(); + + assert_eq!(*req.headers(), HeaderMap::default()); +}