cargo-docserver icon indicating copy to clipboard operation
cargo-docserver copied to clipboard

make_index breaks relative links

Open asomers opened this issue 4 years ago • 0 comments

If make_index detects that the browser left off the final "index.html", for example when requesting "http://MYHOST:4000/MYCRATE", it will append "/index.html" when it looks for the file on disk. The returned response's body will look correct. However, all relative links will be formatted wrong. If the user clicks on one, he'll be directed to a nonexistent URL. For example:

  1. If I browse to http://MYHOST:4000/nix, I'll see the familiar doc index for the nix crate
  2. But if I click on a href="fcntl/index.html link, the browser actually interprets it as http://MYHOST:4000/fcntl/index.html, which does not exist.

The correct solution, when the user requests a directory URI instead of a file, would be to return a 302 redirect pointing to the index.html file.

asomers avatar Oct 16 '21 20:10 asomers