Always preserve query string on redirects#703
Conversation
Changed Files
|
There was a problem hiding this comment.
Preserving the query string for redirect is a good idea.
As I wrote in #700 (comment), we should add the query string if available by default to work out of the box.
IMO, this does not represent a "breaking change" per se, but it will enhance what users already have instead.
Here are some adjustments to make:
- Change the
masterbranch target to2.x. As themasternow points to the upcoming v3 (in development). Unless you really wanted your changes to be included in a future v3 release? - Let's include the query string in the redirect by default if present.
- Let's adjust the tests so we assert this behaviour.
- Revert the new option for redirect query support as we want it built-in.
There was a problem hiding this comment.
The docs have been moved to another repo. You can revert those changes here and make another PR mentioning this change in the new repo. You can find it at https://github.com/static-web-server/docs/tree/master/src/v2.
There was a problem hiding this comment.
Here's the PR for documentation changes: static-web-server/docs#6.
|
Sounds reasonable! One thing I hadn't quite thought of when implementing this which might be more important to deal with if this changes default behavior rather than being opt-in is what do to when the destination already has a query string, e.g.: [[advanced.redirects]]
source = "/index.html"
destination = "https://static-web-server.net/?src=some-value"
kind = 302Apache has a QSA option for merging the query strings (the default is to always use the one from destination). There's also QSD for the case where destination doesn't have a query string, causing Apache to drop any source query strings (what SWS does now). I'd lean toward a QSA-like behavior by default, what do you think? |
I believe QSA-like behavior by default is fine too if the query string is present, of course. Let's go with that then. |
1d794ab to
0e79439
Compare
|
Great! I've updated the PR and re-targeted it to |
joseluisq
left a comment
There was a problem hiding this comment.
A minor improvement to make.
Updates the redirection logic to preserve query strings sent by the client when performing redirects. The query string is appended verbatim to the Location header after matching; if the destination already has a query string the one from the client is appended. This mimics the QSA rewrite option offered by Apache, and should be fairly backward-compatible with existing configurations. Closes #700
e52e0f9 to
83b1c25
Compare
joseluisq
left a comment
There was a problem hiding this comment.
Looks ok to me.
Thanks!
Description
Adds a new preserve-query option to redirects which causes SWS to append any query string received verbatim to the Location header when redirecting. This setting is optional, defaulting to false, which retains existing behavior for backward-compatibility.
Related Issue
#700
Motivation and Context
How Has This Been Tested?
Unit and integration tests have been written and pass (on Arch Linux, amd64, rustc 1.91.1).
Screenshots (if appropriate):