purge: fail to purge with query string #353
Merged
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.
A customer discovered purging URLs, that contained a query param, would fail to purge.
In the following example, the first URL would purge while the other two would not purge.
Following a quick review of the API client code I discovered that the
.Post()
method internally calls.Request()
, and that internally calls.RawRequest()
. It's in that last method we see this:go-fastly/fastly/request.go
Lines 44 to 48 in f56c86d
Because the top-level
Purge()
method isn't settingro.Params
(which are passed all the way through toRawRequest()
), it means the inner most method will replace any query string values withparams.Encode()
, which is going to be an empty string as there is noro.Param
content to iterate over and subsequently we never callparams.Add
to populate theparams
type, and thusparams.Encode()
returns an empty string.The fix is to ensure the
Purge()
method parses the given URL and extracts its query string (if any) and assigns it toro.Params
so it's passed down toRawRequest()
so the internal method can re-apply it as necessary.