Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

HTTP20Connection.request has no mechanism to send duplicate headers #437

@bneradt

Description

@bneradt

The HTTP20Connection.request takes a dictionary of headers. This is problematic because, far as I can tell, this prevents the ability to send a request with duplicate headers (multiple header fields with the same name). The spec explicitly allows for duplicate headers. See for example RFC 7541 section 2.3.2:

The dynamic table can contain duplicate entries (i.e., entries with the same name and same value). Therefore, duplicate entries MUST NOT be treated as an error by a decoder.

h2.H2Connection.send_headers addresses this by taking an iterable of tuples, allowing for duplicates:

headers (An iterable of two tuples of bytestrings or HeaderTuple objects.) – The request/response headers to send.

Can request be updated to allow for the same (i.e., an iterable of tuples)? As a suggestion, I believe this can easily be done in the implementation here:

all_headers = headers.items()

We can wrap that in a try/except block, handling AttributeError to simply set all_headers to headers. Something like:

    try:
        all_headers = headers.items()
    except AttributeError:
        all_headers = headers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions