Skip to content
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

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

Merged
merged 2 commits into from
May 6, 2023

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