Why is an empty req.url.qs "truthy"?
According to the docs, you can just test values in a statement and expect it to evaluate it in a "truthy" manner - for example the https://docs.fastly.com/vcl/functions/if/ provides a ternary that I am trying to use based off the the query string req.url.qs
Full context, we're trying to redirect people with no trailing slashes. According to the docs, this should work:
req.url.qs evaluates to true because the variable will always exist, it's just that sometimes it's empty. I think if you change your conditional to check if the query string is empty, this operator will behave the way you want:
set req.url = req.url.path + "/" + if(req.url.qs != "", "?" + req.url.qs, "");
If you'd like to try that out further, here's a fiddle I made that set that up for your testing. Feel free to clone the fiddle to make any changes you want to test out.
Please let me know if you have any follow up questions or concerns. If you have a specific programmatic need, always feel free to open up a ticket with support at firstname.lastname@example.org. We love digging into these kinds of questions!
Please sign in to leave a comment.