Skip to content

Allow using reqwest without serde #2823

@CathalMullan

Description

@CathalMullan

Currently, reqwest uses serde in three places that are not behind feature flags:

  • Request query parameters query<T>
  • Request form data form<T>
  • WASM header parsing

It would be nice to make serde usage entirely optional.

The two request methods could be moved to optional (enabled by default) features query, form.
And the WASM parsing could be replaced with native JS methods.

There's been asks in the past to change the behavior of the query/form methods:

This would at least provide an option to disable those built-in APIs.

For the WASM usage, the current approach converts headers to JSON, then parses them with serde_json, in order to extract them as strings.
I imagine there's a simpler way to do that without reaching for serde.

reqwest/src/wasm/client.rs

Lines 264 to 269 in da0702b

let serialized_headers: String = JSON::stringify(&item)
.expect_throw("serialized headers")
.into();
let [name, value]: [String; 2] = serde_json::from_str(&serialized_headers)
.expect_throw("deserializable serialized headers");
resp = resp.header(&name, &value);

Note that serde would still be pulled in as a transitive dependency through url due to a bug.
But that should be resolved once servo/rust-url#1071 is released.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions