Skip to content

Commit e9c1c5d

Browse files
committed
Make /crate/:crate/latest/builds.json not strip .json suffix
1 parent 12b591c commit e9c1c5d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/web/builds.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@ pub fn build_list_handler(req: &mut Request) -> IronResult<Response> {
4343
let mut conn = extension!(req, Pool).get()?;
4444
let limits = ctry!(req, Limits::for_crate(&mut conn, name));
4545

46+
let is_json = req.url.path().join("/").ends_with(".json");
47+
4648
let version =
4749
match match_version(&mut conn, name, req_version).and_then(|m| m.assume_exact())? {
4850
MatchSemver::Exact((version, _)) => version,
4951

5052
MatchSemver::Semver((version, _)) => {
53+
let ext = if is_json { ".json" } else { "" };
5154
let url = ctry!(
5255
req,
5356
Url::parse(&format!(
54-
"{}/crate/{}/{}/builds",
57+
"{}/crate/{}/{}/builds{}",
5558
redirect_base(req),
5659
name,
57-
version
60+
version,
61+
ext
5862
)),
5963
);
6064

@@ -95,7 +99,7 @@ pub fn build_list_handler(req: &mut Request) -> IronResult<Response> {
9599
})
96100
.collect();
97101

98-
if req.url.path().join("/").ends_with(".json") {
102+
if is_json {
99103
let mut resp = Response::with((status::Ok, serde_json::to_string(&builds).unwrap()));
100104
resp.headers.set(ContentType::json());
101105
resp.headers.set(Expires(HttpDate(time::now())));

0 commit comments

Comments
 (0)