Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cargo/ops/registry/mod.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discuss in #15592 before proceeding. Thank you.

Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ fn registry<'gctx>(
} else {
None
};
let handle = http_handle(gctx)?;
let mut handle = http_handle(gctx)?;
handle.follow_location(true)?;
Ok((
Registry::new_handle(api_host, token, handle, cfg.auth_required),
src,
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,34 @@ fn auth_required() {
.with_stdout_data(SEARCH_RESULTS)
.run();
}

#[cargo_test]
fn follows_redirect() {
let _registry = RegistryBuilder::new()
.http_api()
.add_responder("/api/v1/crates", |req, _server| {
let query = req.url.query().unwrap_or("");
let redirect_url = format!("/api/v1/crates/redirected?{}", query);
Response {
code: 302,
headers: vec![format!("Location: {}", redirect_url)],
body: vec![],
}
})
.add_responder("/api/v1/crates/redirected", |_, _| Response {
code: 200,
headers: vec![],
body: SEARCH_API_RESPONSE.to_vec(),
})
.build();

cargo_process("search postgres")
.replace_crates_io(&_registry.index_url())
.with_stdout_data(SEARCH_RESULTS)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[NOTE] to learn more about a package, run `cargo info <name>`

"#]])
.run();
}