-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a way to set fallback file extensions for
FileService
(#5806)
Motivation: I prefer clean URL patterns without a trailing slash so `/app/projects` is preferred over `/app/projects/`. If I built `/app/projects` with a Javascript framework, `/app/projects/index.html` or `/app/projects.html` may be exported by the framework which is a common feature. In `FileService`, `/app/projects/index.html` can be served by `/app/projects/` path, but cannot be found by `/app/projects`. A trailing slash `/` can be converted into `/index.html` or an auto index page. As some fallback logics are already implemented, I didn't want to add a new fallback option for a trailing slash. Alternatively, I propose an option that appends an extension if there is no file for the request path. For example, a request sent to `/app/projects` also finds `/app/projects.[ext]` as a fallback. Related links: - #4542 - #1655 - https://ktor.io/docs/server-static-content.html#extensions Modifications: - Allow configuring `fallbackFileExtensions()` via `FileServiceBuilder` - Find a file with fallback extensions if missing. Result: - You can now set fallback file extensions to look up files in `FileService`. ```java FileService .builder(rootDir) .fallbackFileExtensions("html", "txt") ... ``` - Closes #4542
- Loading branch information
Showing
4 changed files
with
178 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters