Skip to content

Design an internal per-request config system #2641

@seanmonstar

Description

@seanmonstar

The client builder provides a lot of configuration options. It's really convenient to be able to configure once and have all requests use that. But it's also very very common for users to ask to be able to customize one of the options just for a single request. It feels wasteful that the current solution is to create a separate Client, since they're not free.

Some of those feature requests:

Instead of adding support ad-hoc (well, we already did add one option, but before it gets worse), I'd like to come up with an easy internal system to support all sorts of config. I suspect the best way would be to store options in the request extensions, and then change the pattern of access self.client.config.blah to something like ReadTimeout::get(&req, &client), which will know to look in the request extensions first, and then look on the client if it isn't set.

To start off:

  • Add an http::Extensions field to Request.
  • Change Request to store the optional timeout in the extensions.
  • Design a system or pattern or trait or something (internally facing) so that we always look in the request before checking the client config, to reduce accidentally forgetting to check the request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-rfcBlocked: Request for comments. More discussion would help move this along.C-refactorCategory: refactor. This would improve the clarity of internal code.E-pr-welcomeThe feature is welcome to be added, instruction should be found in the issue.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions