Skip to content

Commit 214710f

Browse files
committed
Give precedence to local shared files over global ones
When serving 'essential files', we can either serve the global one, created when building `empty_library`, or the local one, created when building the local crate. Currently we default to the global one, but this causes issues when the file should never have been global in the first place (such as recently for `crates.js`: see #1313). This gives precedence to the local file so that the bug will be fixed when rustdoc fixes it, even if we forget to update `ESSENTIAL_FILES_UNVERSIONED`.
1 parent 4ee9d89 commit 214710f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/web/mod.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,23 @@ impl Handler for CratesfyiHandler {
171171
}
172172
}
173173

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

0 commit comments

Comments
 (0)