Skip to content

Commit 2d17280

Browse files
committed
crates-io: Set Content-Type: application/json only for requests with a body payload
1 parent 8859998 commit 2d17280

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

crates/crates-io/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ impl Registry {
389389
self.handle.url(&format!("{}/api/v1{}", self.host, path))?;
390390
let mut headers = List::new();
391391
headers.append("Accept: application/json")?;
392-
headers.append("Content-Type: application/json")?;
392+
if body.is_some() {
393+
headers.append("Content-Type: application/json")?;
394+
}
393395

394396
if self.auth_required || authorized == Auth::Authorized {
395397
headers.append(&format!("Authorization: {}", self.token()?))?;

src/doc/src/reference/registry-web-api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ be required in the future.
4040

4141
Cargo sets the following headers for all requests:
4242

43-
- `Content-Type`: `application/json`
43+
- `Content-Type`: `application/json` (for requests with a body payload)
4444
- `Accept`: `application/json`
4545
- `User-Agent`: The Cargo version such as `cargo 1.32.0 (8610973aa
4646
2019-01-02)`. This may be modified by the user in a configuration value.

0 commit comments

Comments
 (0)