Skip to content

docs.rs/std/<path>?<args> should redirect path and args to doc.rust-lang #751

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

Closed
tinaun opened this issue May 8, 2020 · 12 comments · Fixed by #1816
Closed

docs.rs/std/<path>?<args> should redirect path and args to doc.rust-lang #751

tinaun opened this issue May 8, 2020 · 12 comments · Fixed by #1816
Labels
E-easy Effort: Should be easy to implement and would make a good first PR mentor This has instructions for getting started S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.

Comments

@tinaun
Copy link

tinaun commented May 8, 2020

it trips me up when docs.rs/std/ works but docs.rs/std/io doesn't

@jyn514 jyn514 added the E-easy Effort: Should be easy to implement and would make a good first PR label May 8, 2020
@jyn514
Copy link
Member

jyn514 commented May 8, 2020

Mentoring instructions:

  • In build_routes, for each redirect to doc.rust-lang.org, add a route for /{route}/*

for redirect in DOC_RUST_LANG_ORG_REDIRECTS {

  • Change RustLangRedirector to accept routes other than a &'static str. You will have to refactor it slightly since it currently always redirects to a fixed URL instead of basing it off the request.

impl RustLangRedirector {

fn standard_library_redirects() {

If you have any questions, feel free to ask here or on Discord!

@jyn514 jyn514 added the mentor This has instructions for getting started label May 8, 2020
@robinhundt
Copy link
Contributor

This looks like something I'd definitely use myself. I'll start working on this.

@robinhundt
Copy link
Contributor

Mhh, so something weird is going on. I first tried adding a new internal_page route just using the current RustLangRedirector:

    for redirect in DOC_RUST_LANG_ORG_REDIRECTS {
        routes.internal_page(
            &format!("/{}", redirect),
            super::rustdoc::RustLangRedirector::new(redirect),
        );
        routes.internal_page(
            &format!("/{}/*", redirect),
            super::rustdoc::RustLangRedirector::new(redirect),
        );
    }

https://github.com/robinhundt/docs.rs/blob/2638dca77ad0beee7c2399485f0ceb2bdcfc5a25/src/web/routes.rs#L127-L136

Unfortunately this doesn't seem to work. E.g. going to /std/io/ results in a crate not found. /std/ continues to redirect. The interesting thing is that both

routes.internal_page(
    &format!("/{}/:something", redirect),
    super::rustdoc::RustLangRedirector::new(redirect),
);

and

routes.internal_page(
    &format!("/{}/test", redirect),
    super::rustdoc::RustLangRedirector::new(redirect),
);

will redirect for the corresponding GET requests.
At first I thought it had something to do with the BlockBlacklistedPrefixes handler, but that is run in the handler chain before the routes handler and the 404 it returns should just be ignored. (By the way, I found some dead code that looks fishy here: https://github.com/robinhundt/docs.rs/blob/2638dca77ad0beee7c2399485f0ceb2bdcfc5a25/src/web/routes.rs#L174-L184 rustdoc_get is never not empty as far as I can tell).

So then I thought it might be a bug in the old version of the router lib that is used, but this small repo https://github.com/robinhundt/test-iron-router/blob/master/src/main.rs seems to suggest that that is not the case, since the wildcard works just fine there.

So I'm a little bit stumped as to why the handler is called for the normal or match pattern but not for the wildcard one.

@Nemo157
Copy link
Member

Nemo157 commented Sep 12, 2020

It may still be a bug in the router, maybe related to http-rs/route-recognizer#20 causing the priorities between the different routes to be wrong (I'm actually surprised that docs.rs has not hit this yet, on my other iron using project I encountered it almost straight away).

@jyn514
Copy link
Member

jyn514 commented Sep 12, 2020

Try updating the router, then? It looks like that issue was fixed in a later version.

@Nemo157
Copy link
Member

Nemo157 commented Sep 12, 2020

It's fixed in the underlying library the router uses, but afaik iron's router itself hasn't updated that library.

@jyn514
Copy link
Member

jyn514 commented Sep 12, 2020

Hmm, we might be able to use patch.crates-io but at that point it's getting a little hacky.

@robinhundt
Copy link
Contributor

robinhundt commented Sep 13, 2020

@Nemo157 you're right. It seems to be the route

    routes.rustdoc_page(
        "/:crate/:version",
        super::rustdoc::rustdoc_redirector_handler,
    )

that is more specific than /static/*.
I thought sending a PR for iron/router shouldn't be to difficult... turns out the master branch doesn't even compile when testing due to #![cfg_attr(test, deny(warnings))] and usage of Error::description and after disabling that there is a failing test case related to query parameter handling :/
So it seems that in order to fix this problem, first iron/router needs it's dependencies updated which would probably result in a new breaking release.

@jyn514
Copy link
Member

jyn514 commented Sep 13, 2020

Iron isn't really maintained, so I'm not sure how realistic it is to wait for that PR to be merged ... it's also unlikely they'd backport to 0.5, which we're still stuck on. I think this needs either a different approach in docs.rs or to wait for the switch to hyper (#747).

@jyn514 jyn514 added the S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work. label Sep 13, 2020
@Kixiron
Copy link
Member

Kixiron commented Sep 15, 2020

Trying to get fixes into iron is probably a lost cause, like Joshua said. We can't move to 0.6 because of mysterious panics and some fun compile errors so even if they got in, we couldn't benefit from them

@robinhundt
Copy link
Contributor

Mhh, that's unfortunate. In the meantime we could use the pattern /static/:module to redirect to top-level modules of the standard library so that it at least works for that case. Although I'm not sure if it makes sense to introduce half-baked code for this, I assume, low priority feature, if there are major refactors due to the switch to hyper in the works anyway.

@Nemo157
Copy link
Member

Nemo157 commented Aug 30, 2022

I'm working on this now so that we can have the new https://docs.rs/std::vec like urls too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Effort: Should be easy to implement and would make a good first PR mentor This has instructions for getting started S-blocked Status: marked as blocked ❌ on something else such as an RFC or other implementation work.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants