Skip to content

Commit e8d197f

Browse files
authored
fix: filter http query_args and convert only supported values (#394)
1 parent 195b6e7 commit e8d197f

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Information about release notes of Coco Server is provided here.
3131
- fix: active shadow setting #354
3232
- fix: chat history was not show up #377
3333
- fix: get attachments in chat sessioins
34+
- fix: filter http query_args and convert only supported values
3435

3536
### Improvements
3637

src-tauri/src/server/http_client.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,23 @@ impl HttpClient {
8282
}
8383

8484
if let Some(query) = query_params {
85-
let query: HashMap<String, String> =
86-
query.into_iter().map(|(k, v)| (k, v.to_string())).collect();
85+
// Convert only supported value types into strings
86+
let query: HashMap<String, String> = query
87+
.into_iter()
88+
.filter_map(|(k, v)| {
89+
match v {
90+
JsonValue::String(s) => Some((k, s)),
91+
JsonValue::Number(n) => Some((k, n.to_string())),
92+
JsonValue::Bool(b) => Some((k, b.to_string())),
93+
_ => {
94+
dbg!(
95+
"Unsupported query parameter type. Only strings, numbers, and booleans are supported.",k,v,
96+
);
97+
None
98+
} // skip arrays, objects, nulls
99+
}
100+
})
101+
.collect();
87102
request_builder = request_builder.query(&query);
88103
}
89104

@@ -169,7 +184,7 @@ impl HttpClient {
169184
query_params,
170185
body,
171186
)
172-
.await
187+
.await
173188
}
174189

175190
// Convenience method for PUT requests
@@ -189,7 +204,7 @@ impl HttpClient {
189204
query_params,
190205
body,
191206
)
192-
.await
207+
.await
193208
}
194209

195210
// Convenience method for DELETE requests
@@ -208,6 +223,6 @@ impl HttpClient {
208223
query_params,
209224
None,
210225
)
211-
.await
226+
.await
212227
}
213228
}

0 commit comments

Comments
 (0)