Remove unnecessary .to_string() call when creating a header from JSON data

The original version would double quote values, resulting in serde_json inserting
escape characters into the final string value, which prevented the header from
being parsed by htmx properly.
This commit is contained in:
Rob Wagner 2023-10-23 22:52:01 -04:00
parent 81b9c548b3
commit a1bac4b30e
No known key found for this signature in database
GPG key ID: 53CCB4497B15CF61

View file

@ -193,8 +193,9 @@ pub(crate) fn events_to_header_value(events: Vec<HxEvent>) -> Result<HeaderValue
// encoded.
let header_value = events
.into_iter()
.map(|e| (e.name, e.data.map(|d| d.to_string()).unwrap_or_default()))
.collect::<HashMap<_, _>>();
.map(|e| (e.name, e.data.unwrap_or_default()))
.collect::<HashMap<String, Value>>();
serde_json::to_string(&header_value)?
} else {
// no event contains data, the event names can be put in the header