tower-rs / tower-http

HTTP specific Tower utilities.
675 stars 156 forks source link

Option to prepend a path for redirects in `ServeDir` #487

Closed maxi0604 closed 4 months ago

maxi0604 commented 4 months ago

Feature Request

Motivation

Currently ServeDir assumes that the files are served from /, which breaks trailing slash redirects in some configurations like a reverse proxy that redirects /somePath/* to the ServeDir server or a scenario where axum::Router::nest_service is used.

Proposal

Allow this to be configured, see #486

Alternatives

NormalizePathLayer doesn't work, since it removes the trailing slash and hence always triggers the TSR. Whether to perform the redirect depends on the files served (whether the requested path leads to a file or directory) so it seems reasonable to implement this in ServeDir.

A similar argument applies to axum_extras function route_with_tsr

maxi0604 commented 4 months ago

Ooops, the issue has already been reported here: #413