benchttp/runner

Add config option `Request.Headers`

Closed this issue · 2 comments

Description

We must be able to configure the request's headers.

Tasks

  • provide the headers
  • set the headers in Requester.Do
  • support config file
  • support flag args

Suggestions

Internally represent the headers with map[string][]string.

The yaml structure may resemble this:

headers:
  - content-type: "text/plain"
  - authorization: "Basic  YWxhZGRpbjpvcGVuc2VzYW1l"

Via cli, the input could look like:

benchttp --header key:value --header key:value

Repeat flag for multiple headers

Notes

Many unknowns regarding content-type. Must be handle in sync with #32.

We need to establish the desired behaviour when using header both in config file and in the CLI:

  • erase all headers from the config file as soon as any header is set via the CLI ➡️ CLI keeps its overriding role, but the user can't just add one header (needs to re-write all of them)
  • never erase, just append the values from CLI instead ➡️ easier to add a single value, but no way to override via CLI
  • override only the values whose key is set via the CLI ➡️ kinda hybrid approach, allows both overriding and simple additions

Third option is probably the most suitable - but also the least straightforward implementation.

After discussion, we go for option 3.