Skip to content

Commit 341baae

Browse files
committed
fix(search): follow http redirects
Fixes rust-lang#15592
1 parent 68db374 commit 341baae

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/cargo/ops/registry/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ fn registry<'gctx>(
169169
} else {
170170
None
171171
};
172-
let handle = http_handle(gctx)?;
172+
let mut handle = http_handle(gctx)?;
173+
handle.follow_location(true)?;
173174
Ok((
174175
Registry::new_handle(api_host, token, handle, cfg.auth_required),
175176
src,

tests/testsuite/search.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,34 @@ fn auth_required() {
224224
.with_stdout_data(SEARCH_RESULTS)
225225
.run();
226226
}
227+
228+
#[cargo_test]
229+
fn follows_redirect() {
230+
let _registry = RegistryBuilder::new()
231+
.http_api()
232+
.add_responder("/api/v1/crates", |req, _server| {
233+
let query = req.url.query().unwrap_or("");
234+
let redirect_url = format!("/api/v1/crates/redirected?{}", query);
235+
Response {
236+
code: 302,
237+
headers: vec![format!("Location: {}", redirect_url)],
238+
body: vec![],
239+
}
240+
})
241+
.add_responder("/api/v1/crates/redirected", |_, _| Response {
242+
code: 200,
243+
headers: vec![],
244+
body: SEARCH_API_RESPONSE.to_vec(),
245+
})
246+
.build();
247+
248+
cargo_process("search postgres")
249+
.replace_crates_io(&_registry.index_url())
250+
.with_stdout_data(SEARCH_RESULTS)
251+
.with_stderr_data(str![[r#"
252+
[UPDATING] crates.io index
253+
[NOTE] to learn more about a package, run `cargo info <name>`
254+
255+
"#]])
256+
.run();
257+
}

0 commit comments

Comments
 (0)