Skip to content

Commit

Permalink
crates-io: Set Content-Type: application/json only for requests wit…
Browse files Browse the repository at this point in the history
…h a body payload
  • Loading branch information
Turbo87 committed Jan 9, 2024
1 parent 8859998 commit 2d17280
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion crates/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?))?;
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/reference/registry-web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2d17280

Please sign in to comment.