Skip to content

Support duplicate custom request headers #2503

@ayanrajpoot10

Description

@ayanrajpoot10

Please describe your feature request:

Currently, httpx does not support sending multiple custom headers with the same name. When -H is used multiple times for the same header (for example, -H "Test: 1" -H "Test: 2"), only the last value is preserved.

This happens because custom headers are currently stored using map[string]string, which only allows a single value per header name. To support duplicate headers properly, this should be changed to map[string][]string, similar to Go's standard http.Header implementation.

Additionally, r.Header.Set() should be replaced with r.Header.Add() so that all provided header values are included in the request instead of overwriting previous ones.

Describe the use case of this feature:

The HTTP protocol allows multiple header fields with the same name in certain cases. A common example is Set-Cookie, where multiple separate header entries are expected.

Standard tools like curl already support this behavior when multiple -H flags are provided for the same header. Go's own http.Header type is also implemented as map[string][]string for this reason.

Metadata

Metadata

Assignees

Labels

Type: EnhancementMost issues will probably ask for additions or changes.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions