api: Fix inverse condition for sending application/json content-type

This commit is contained in:
Jonas Platte 2021-09-21 18:54:10 +02:00
parent 21e4c90cfa
commit 7df5a0f09d
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
3 changed files with 20 additions and 4 deletions

View File

@ -102,14 +102,14 @@ impl Request {
// policies that don't allow the `Content-Type` header (for things such as `.well-known` // 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). // 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() { let mut header_kvs = if self.raw_body_field().is_some() || self.has_body_fields() {
TokenStream::new()
} else {
quote! { quote! {
req_headers.insert( req_headers.insert(
#http::header::CONTENT_TYPE, #http::header::CONTENT_TYPE,
#http::header::HeaderValue::from_static("application/json"), #http::header::HeaderValue::from_static("application/json"),
); );
} }
} else {
TokenStream::new()
}; };
header_kvs.extend(self.header_fields().map(|request_field| { header_kvs.extend(self.header_fields().map(|request_field| {

View File

@ -1,7 +1,5 @@
# [unreleased] # [unreleased]
# 0.18.4
Bug fixes: Bug fixes:
* Stop adding a `Content-Type` header to requests without any fields * 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 environment if the server isn't configured to allow that header for
cross-origin requests cross-origin requests
# 0.18.4
Yanked.
# 0.18.3 # 0.18.3
Improvements: Improvements:

View File

@ -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<Vec<u8>> = discover_homeserver::Request::new()
.try_into_http_request("https://homeserver.tld", SendAccessToken::None)
.unwrap();
assert_eq!(*req.headers(), HeaderMap::default());
}