Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give precedence to local shared files over global ones #1324

Merged
merged 1 commit into from
Mar 21, 2021
Merged
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
21 changes: 16 additions & 5 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,23 @@ impl Handler for CratesfyiHandler {
}
}

// try serving shared rustdoc resources first, then db/static file handler and last router
// return 404 if none of them return Ok. It is important that the router comes last,
// because it gives the most specific errors, e.g. CrateNotFound or VersionNotFound
self.shared_resource_handler
// This is kind of a mess.
//
// Almost all files should be served through the `router_handler`; eventually
// `shared_resource_handler` should go through the router too, and `database_file_handler`
// could be removed altogether.
//
// Unfortunately, combining `shared_resource_handler` with the `router_handler` breaks
// things, because right now `shared_resource_handler` allows requesting files from *any*
// subdirectory and the router requires us to give a specific path. Changing them to a
// specific path means that buggy docs from 2018 will have missing CSS (#1181) so until
// that's fixed, we need to keep the current (buggy) behavior.
//
// It's important that `router_handler` comes first so that local rustdoc files take
// precedence over global ones (see #1324).
self.router_handler
.handle(req)
.or_else(|e| if_404(e, || self.router_handler.handle(req)))
.or_else(|e| if_404(e, || self.shared_resource_handler.handle(req)))
.or_else(|e| if_404(e, || self.database_file_handler.handle(req)))
.or_else(|e| {
let err = if let Some(err) = e.error.downcast_ref::<error::Nope>() {
Expand Down