Skip to content

httpx does not allow header values with trailing spaces #1640

Closed

Description

@perkfly
httpx.get("http://example.com", headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) Gecko/20100101 Firefox/63.0 "})  # note the trailing space
LocalProtocolError: Illegal header value b'Mozilla/5.0 (Windows NT 6.1; WOW64) Gecko/20100101 Firefox/63.0 '

requests.get("http://example.com", headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) Gecko/20100101 Firefox/63.0 "})
<Response [200]>

Activity

  1. uriyyo commented on May 16, 2021

    @uriyyo

    Hi @yeraydiazdiaz,

    Actually, it is not a problem with httpx.
    h11 library raise this exception so I think this issue should be transferred from httpx to h11.

  2. lovelydinosaur commented on May 17, 2021

    @lovelydinosaur
    Member

    So, h11 is raising an error here because trailing spaces in HTTP headers is a spec violation.

    (I mean, I haven't double checked that yet, but it's almost certainly why)

    The first question to ask would be - do you actually need this, and if so why?

    Presumably the sensible thing for us to do would be either:

    • Continue to raise an error here, because it's an invalid HTTP header value.
    • Silently strip any trailing whitespace in HTTP header values.

    Although I'd be curious to hear if there's any valid use cases where folks actually need the trailing whitespace for some reason.

  3. locked and limited conversation to collaborators on May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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