Fix event_type array query parsing #810
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.
This fixes how
?event_types
query parameters are parsed in*/attempt/endpoint/*
, in addition to some adjacent refactors.Motivation
axum::Query
doesn't support URL query array parameter parsing very well. For example,?a=1&a=2
gets rejected?a[]=1&a[]=2
also gets rejected?a[0]=1&a[1]=2
also gets rejectedThis is largely because
serde::urlencoded
doesn't support any of these formats. See nox/serde_urlencoded#75There is
serde_qs
, which supports the last two. But not the first format. See samscott89/serde_qs#16Unfortunately, we need to support the first format because that is what our internal API has supported up to today.
However, our OSS has been inconsistent. Specifically with
?event_types
.Most endpoints that took in
?event_types
usedMessageListFetchOptions
, which manually parsed?event_types
only using the first format. Ideally, we'd like to support all 3.In addition,
*/attempts/endpoint/
didn't useMessageListFetchOptions
. Instead it relied onaxum::Query
deserialization, so?event_types
outright didn't work as expected with this endpoint.Solution
This PR does a couple small things to fix these issues
MessageListFetchOptions
is axed in favor of a more explicitEventTypesQuery
.MessageListFetchOptions
had an extra timestamp parameter,before
, that is already parsed just fine byaxum::Query
.EventTypesQuery
is similar toMessageListFetchOptions
, in respect to howevent_types
are parsed. With a few exceptionsEventTypesQuery
validates the input.EventTypesQuery
handles all 3 formats, not just the first oneEventTypesQuery
should be a bit more performant, since it usesform_urlencode
, which parses pairs asCow<str>
, so fewer allocations. (Note thatform_urlencode
is whatserde_urlencoded
uses under the hood)*/attempts/endpoint/
to useEventTypesQuery
, so that?event_types
are parsed correctly. Tests are added to demonstrate and validate this behavior.