Skip to content

ServeDir in nested route causes invalid redirects #1731

Open
@yu-re-ka

Description

@yu-re-ka
  • I have looked for existing issues (including closed) about this

Bug Report

Version

├── axum v0.5.13
│   ├── axum-core v0.2.7
│   ├── tower-http v0.3.4
└── tower-http v0.3.4 (*)

Platform

Linux yaya 6.1.7 #1-NixOS SMP PREEMPT_DYNAMIC Wed Jan 18 10:58:34 UTC 2023 x86_64 GNU/Linux

Description

https://yaya.yuka.dev/ is running a axum based webserver with a axum::Router. It has a nest route for /public that contains a ServeDir service with path /mnt/public/.

Now, in /mnt/public/, there exists an empty directory /mnt/public/foo.
I request https://yaya.yuka.dev/public/foo
And I get:

< HTTP/2 307 
< location: https://yaya.yuka.dev/foo/

while I would have expected a redirect to https://yaya.yuka.dev/public/foo/

This redirect is created here in ServeDir, and it uses the stripped path instead of the original uri to determine the redirect location.

Unsure how to solve this, but some ideas:

  • maybe the StripPrefix middleware and OriginalUri could be moved to tower_http and then tower_http can try to use the OriginalUri first and then fall back to the req.uri().

  • Or the nested route service could attempt to rewrite relative redirects, but that seems like it would not generally work since applications behind a reverse proxy could also have other ways of redirecting

  • Or ServeDir could be configured with a static prefix that is added to the redirects

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-axumC-bugCategory: This is a bug.E-hardCall for participation: Experience needed to fix: Hard / a lot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions