Skip to content

Commit 1cfbb52

Browse files
committed
Log when a file is not served because it was too big
1 parent cab5014 commit 1cfbb52

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/storage/s3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ impl S3Backend {
103103
.ok_or_else(|| failure::err_msg("Received a response from S3 with no body"))?;
104104

105105
while let Some(data) = body.next().await.transpose()? {
106-
content.write_all(data.as_ref())?;
106+
if let Err(err) = content.write_all(data.as_ref()) {
107+
return Err(Error::from(err).context("file too large; refusing to serve").into());
108+
}
107109
}
108110

109111
let date_updated = parse_timespec(&res.last_modified.unwrap())?;

src/web/rustdoc.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,20 @@ pub fn rustdoc_html_server_handler(req: &mut Request) -> IronResult<Response> {
298298
}
299299

300300
// Attempt to load the file from the database
301-
let file = if let Ok(file) = File::from_path(&storage, &path, &config) {
302-
file
303-
} else {
304-
// If it fails, we try again with /index.html at the end
305-
path.push_str("/index.html");
306-
req_path.push("index.html");
307-
308-
return if ctry!(req, storage.exists(&path)) {
309-
redirect(&name, &version, &req_path[3..])
310-
} else {
311-
Err(IronError::new(Nope::ResourceNotFound, status::NotFound))
312-
};
301+
let file = match File::from_path(&storage, &path, &config) {
302+
Ok(file) => file,
303+
Err(err) => {
304+
log::debug!("got error serving {}: {}", path, err);
305+
// If it fails, we try again with /index.html at the end
306+
path.push_str("/index.html");
307+
req_path.push("index.html");
308+
309+
return if ctry!(req, storage.exists(&path)) {
310+
redirect(&name, &version, &req_path[3..])
311+
} else {
312+
Err(IronError::new(Nope::ResourceNotFound, status::NotFound))
313+
};
314+
}
313315
};
314316

315317
// Serve non-html files directly

0 commit comments

Comments
 (0)