Skip to content

Commit c68ab80

Browse files
committed
Allow arbitrary limits on index
1 parent 9061201 commit c68ab80

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/package.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ impl Package {
147147
}
148148

149149
pub fn index(req: &mut Request) -> CargoResult<Response> {
150-
let limit = 10i64;
151150
let conn = try!(req.tx());
152151
let query = req.query();
153152
let page = query.find_equiv(&"page").map(|s| s.as_slice())
154153
.and_then(from_str::<i64>).unwrap_or(1);
154+
let limit = query.find_equiv(&"per_page").map(|s| s.as_slice())
155+
.and_then(from_str::<i64>).unwrap_or(10);
156+
if limit > 100 { return Err(human("cannot request more than 100 packages")) }
155157
let offset = (page - 1) * limit;
156158
let pattern = query.find_equiv(&"letter")
157159
.map(|s| s.as_slice().char_at(0).to_lowercase())

0 commit comments

Comments
 (0)