Skip to content

fix(http/file_server): Redirect non-canonical URL to canonical URL#3362

Merged
kt3k merged 2 commits intodenoland:mainfrom
ayame113:file-server-normalize-url
May 6, 2023
Merged

fix(http/file_server): Redirect non-canonical URL to canonical URL#3362
kt3k merged 2 commits intodenoland:mainfrom
ayame113:file-server-normalize-url

Conversation

@ayame113
Copy link
Contributor

@ayame113 ayame113 commented May 5, 2023

part of #3361

This PR changes the serveDir()'s behavior so that URLs are canonicalized.
The current behavior and the behavior after the change are as follows.

request before after
/path/to/directory 🟢200 OK 🟡301 redirect to /path/to/directory/
/path/////to/////directory/////// 🟢200 OK 🟡301 redirect to /path/to/directory/
/path/////to/////file.txt 🟢200 OK 🟡301 redirect to /path/to/file.txt
/path/to/file.txt/ 🔴500 Internal Server Error 🟡301 redirect to /path/to/file.txt
/path/////to/////file.txt/ 🔴500 Internal Server Error 🟡301 redirect to /path/to/file.txt
/path/////to/////file.txt///// 🔴500 Internal Server Error 🟡301 redirect to /path/to/file.txt

Also serveDir() currently has 7 nestings (function-try-if-if-try-if-if). I cut this part out into a separate function.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New redirect cases make sense to me. Also this looks nice clean up! LGTM

@kt3k kt3k merged commit 6e8ee3c into denoland:main May 6, 2023
@ayame113 ayame113 deleted the file-server-normalize-url branch May 6, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants