Skip to content

Commit 616bae2

Browse files
committed
Auto merge of #13264 - Turbo87:ct-header, r=weihanglo
crates-io: Set `Content-Type: application/json` only for requests with a body payload ### What does this PR try to resolve? The `Content-Type` **request** header is only supposed to be used if the request comes with a body payload. `cargo` is currently sending it unconditionally, even for `GET` requests that typically don't have a payload attached to them. This PR changes the implementation to only attach the header if the request has a body payload.
2 parents b90f770 + 6218d08 commit 616bae2

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cargo_metadata = "0.18.1"
3737
clap = "4.4.12"
3838
color-print = "0.3.5"
3939
core-foundation = { version = "0.9.4", features = ["mac_os_10_7_support"] }
40-
crates-io = { version = "0.39.0", path = "crates/crates-io" }
40+
crates-io = { version = "0.40.0", path = "crates/crates-io" }
4141
criterion = { version = "0.5.1", features = ["html_reports"] }
4242
curl = "0.4.44"
4343
curl-sys = "0.4.70"

crates/crates-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "crates-io"
3-
version = "0.39.2"
3+
version = "0.40.0"
44
rust-version.workspace = true
55
edition.workspace = true
66
license.workspace = true

crates/crates-io/lib.rs

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)