From ebc52ad870faa30aa6f24db3300cce85a7b1db6b Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Sun, 9 Jul 2023 07:56:58 +0100 Subject: [PATCH] Provides new query param feature of redirects file Draft commit for using https://github.com/ipfs/go-ipfs-redirects-file/pull/21 to allow query parameters in redirects. Cannot be completed/will not be ready until that PR is merged, and a new version released (so go.mod/go.sum can be updated here) --- CHANGELOG.md | 2 ++ gateway/handler_unixfs__redirects.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2926a0a56..8fb87157e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The following emojis are used to highlight certain changes: ## [Unreleased] +* ❔ Allows redirects of URLs by query parameter (in addition to path). A `_redirects` file containing `/from type=:type /to/:type.html 200` will respond to a request of `/from?type=thing` with `/to/thing.html`. + ### Added ### Changed diff --git a/gateway/handler_unixfs__redirects.go b/gateway/handler_unixfs__redirects.go index a96b87d36..afb7859ca 100644 --- a/gateway/handler_unixfs__redirects.go +++ b/gateway/handler_unixfs__redirects.go @@ -99,7 +99,7 @@ func (i *handler) handleRedirectsFileRules(w http.ResponseWriter, r *http.Reques for _, rule := range redirectRules { // Error right away if the rule is invalid - if !rule.MatchAndExpandPlaceholders(urlPath) { + if !rule.MatchAndExpandPlaceholders(urlPath, r.URL.Query()) { continue }