crates-io: Set `Content-Type: application/json` only for requests with a body payload

This commit is contained in:
Tobias Bieniek 2024-01-08 17:29:27 +01:00
parent 88599985e9
commit 2d1728088f
No known key found for this signature in database
2 changed files with 4 additions and 2 deletions

View File

@ -389,7 +389,9 @@ impl Registry {
self.handle.url(&format!("{}/api/v1{}", self.host, path))?;
let mut headers = List::new();
headers.append("Accept: application/json")?;
headers.append("Content-Type: application/json")?;
if body.is_some() {
headers.append("Content-Type: application/json")?;
}
if self.auth_required || authorized == Auth::Authorized {
headers.append(&format!("Authorization: {}", self.token()?))?;

View File

@ -40,7 +40,7 @@ be required in the future.
Cargo sets the following headers for all requests:
- `Content-Type`: `application/json`
- `Content-Type`: `application/json` (for requests with a body payload)
- `Accept`: `application/json`
- `User-Agent`: The Cargo version such as `cargo 1.32.0 (8610973aa
2019-01-02)`. This may be modified by the user in a configuration value.