Skip to content

Commit a642a1c

Browse files
authored
Server: Support comma-separated array query params (#922)
Our Rust lib generates query params in comma-separated syntax. This is technically not what our API expects, but frankly it's easy to support it and seems reasonable to do so. Added and updated tests accordingly. Fixes #921
1 parent 437e828 commit a642a1c

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

server/svix-server/src/v1/utils/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,14 @@ where
563563
let pairs = form_urlencoded::parse(parts.uri.query().unwrap_or_default().as_bytes());
564564

565565
let event_types: HashSet<EventTypeName> = pairs
566-
.filter_map(|(key, value)| {
566+
.filter(|(key, _)|
567567
// want to handle both `?event_types=`, `?event_types[]=`, and `?event_types[1]=`
568-
if key == "event_types" || (key.starts_with("event_types[") && key.ends_with(']')) {
569-
Some(EventTypeName(value.into_owned()))
570-
} else {
571-
None
572-
}
568+
key == "event_types" || (key.starts_with("event_types[") && key.ends_with(']')))
569+
.flat_map(|(_, value)| {
570+
value
571+
.split(',')
572+
.map(|x| EventTypeName(x.to_owned()))
573+
.collect::<Vec<_>>()
573574
})
574575
.collect();
575576

server/svix-server/tests/e2e_attempt.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,23 @@ async fn test_list_attempts_by_endpoint() {
295295
.unwrap();
296296
assert_eq!(regular_attempts.data.len(), 2);
297297

298-
let all_attempts: ListResponse<MessageAttemptOut> = client
298+
let all_attempts_1: ListResponse<MessageAttemptOut> = client
299299
.get(
300300
&format!("api/v1/app/{app_id}/attempt/endpoint/{endp_id_2}/?event_types[0]=event.type&event_types[1]=user.exploded"),
301301
StatusCode::OK,
302302
)
303303
.await
304304
.unwrap();
305-
assert_eq!(all_attempts.data.len(), 3);
305+
assert_eq!(all_attempts_1.data.len(), 3);
306+
307+
let all_attempts_2: ListResponse<MessageAttemptOut> = client
308+
.get(
309+
&format!("api/v1/app/{app_id}/attempt/endpoint/{endp_id_2}/?event_types=event.type,user.exploded"),
310+
StatusCode::OK,
311+
)
312+
.await
313+
.unwrap();
314+
assert_eq!(all_attempts_2.data.len(), 3);
306315

307316
receiver_1.jh.abort();
308317
receiver_2.jh.abort();

0 commit comments

Comments
 (0)