return files directly when serving JS files #349
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After my last docs.rs update over the weekend, i started noticing a handful of panic messages in the docs.rs server log. After hunting it down for a little bit i think i understand the culprit:
search-index.js/aliases.js/source-files.jsroutes from the route table, instead handling them in the baserustdoc_redirector_handler. (Due to a bug inrouter(ultimatelyroute-recognizer) i couldn't create a/:crate/:version/*.jsroute because it would be overridden by the/:crate/:version/:targetroute.) The intent was that routes like/crate/version/search-index.jswould run through the branch i added inrustdoc_redirector_handlerand get loaded up that way.main.jsandstorage.jsare supposed to be caught by theSharedResourceHandlerbefore the route table is even taken into account. However, one important file has been missing there for several rustdoc versions:settings.js. Since this is failing that handler, it's falling into the route table, where it also hitsrustdoc_redirector_handler. Previously it would 404, but now...rustdoc_html_server_handler, where it would start hitting this code here. This is intended to cut off the crate name and version from the URL so that it can format the rest of the path into a path suitable for thefilestable in the database. However, the URLdocs.rs/settings.jsonly has one segment in it. Callingreq_path.remove(0)on it twice will cause it to clear out the path and attempt to index an empty Vec, causing a panic, and a 500 response.This PR adds an extra check to
rustdoc_redirector_handlerto make sure that we try to serve top-level JS files directly instead of sending it throughrustdoc_html_server_handler.