Ensure trailing slash fallback url#197
Merged
jbkempf merged 3 commits intovideolabs:masterfrom Jun 5, 2025
Merged
Conversation
The function `NormalizeURL` is used to ensure that a mirror URL ends with a trailing slash. It's applied when the mirror configuration is written to the database (cf. `setMirror` in `rpc/rpc.go`). Mirrorbits then relies on this fact when it constructs the redirect URLs, in `pagerenderer.go`: ``` path := strings.TrimPrefix(results.FileInfo.Path, "/") [...] http.Redirect([...], results.MirrorList[0].AbsoluteURL+path, http.StatusFound) ``` However, it turns out that `NormalizeURL` is not applied to the fallback URLs. Meaning that if your fallback is `http://mirror.org` and you request the file `foobar`, and if ever the fallback mechanism kicks in, mirrorbits will happily redirect you to `http://mirror.orgfoobar`... Easy to fix! One less papercut!
…kage The previous commit introduced a import cycle: ``` package github.com/etix/mirrorbits imports github.com/etix/mirrorbits/cli from main.go imports github.com/etix/mirrorbits/filesystem from commands.go imports github.com/etix/mirrorbits/config from hash.go imports github.com/etix/mirrorbits/utils from config.go imports github.com/etix/mirrorbits/network from utils.go imports github.com/etix/mirrorbits/config from geoip.go: import cycle not allowed ``` This is because we now import `utils` from within `config`. Let's move the two network-related utils to `network/utils.go`, so that we don't need to import `network` in `utils.go` anymore. That's enough to break the import cycle.
Now that we import `utils` in `config` (cf. previous commits), we can use `IsInSlice` from `utils.go`, no need to duplicate it anymore.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Normalize URL for fallback mirrors, to ensure it ends with a trailing slash. One less papercut for mirrorbits users.