-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
🐛 Fix static middleware subdirectory browsing redirects losing URL prefix #3668
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
Conversation
Co-authored-by: ReneWerner87 <[email protected]>
Co-authored-by: ReneWerner87 <[email protected]>
@copilot Please check the code again and make it smart so that as many cases as possible are handled with as little code as possible and few bugs occur. |
@efectn WDYT is this an edge case ? |
Co-authored-by: ReneWerner87 <[email protected]>
I've refactored the code to be much smarter and simpler as requested. The changes in commit 17f8746: Made it smarter:
Reduced complexity:
Fewer bugs:
All existing tests continue to pass, ensuring the functionality remains intact while achieving significant code simplification. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3668 +/- ##
==========================================
- Coverage 91.84% 91.81% -0.04%
==========================================
Files 113 113
Lines 11447 11490 +43
==========================================
+ Hits 10514 10549 +35
- Misses 669 675 +6
- Partials 264 266 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
fixed by #3673 |
The static middleware with directory browsing enabled was incorrectly handling redirects for subdirectories when URL prefixes were used. When clicking on subdirectory links in the directory listing, the redirect would lose the URL prefix, breaking navigation.
Problem
Consider a Fiber app serving static files with browsing:
Before this fix:
/static
→ shows directory listing with "js" folder/js/
(loses/static
prefix) → 404 errorRoot cause: When fasthttp.FS generates redirects for directory access (to add trailing slashes), it uses the path-rewritten version without the original URL prefix context.
Solution
This fix intercepts redirects generated by fasthttp.FS and corrects the Location header to preserve the URL prefix:
/static/js
→ redirects to/static/js/
(preserves prefix)/static/subfolder
→ redirects to/static/subfolder/
(preserves prefix)The fix handles both absolute and relative redirect URLs and only applies the correction when:
Testing
Added comprehensive tests covering:
All existing tests continue to pass, ensuring backward compatibility.
Fixes #3667.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
exampleretry.com
/tmp/go-build4097136303/b274/client.test -test.paniconexit0 -test.v=test2json -test.timeout=10m0s -test.count=1 -test.shuffle=on
(dns block)/tmp/go-build4063505421/b274/client.test -test.paniconexit0 -test.v=test2json -test.timeout=10m0s -test.count=1 -test.shuffle=on
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.