Skip to content

Any explicit Content-Type header should take precedence over the encoding default. #620

Closed

Description

@daxartio

content_type = "application/json"

I send json argument and content type when i do request, but my content type is replacing to "application/json". I think it is bug

Activity

  1. florimondmanca commented on Dec 9, 2019

    @florimondmanca
    Contributor

    Hi @daxartio,

    What exact use case are you facing that requires passing json=... while setting a Content-Type to something else than application/json?

    As a workaround, using data=... should allow you to set the Content-Type yourself:

    data: bytes = serialize(some_dict)
    r = await httpx.post(url, data=data, headers={"content-type": "application/x-myformat"})
  2. lovelydinosaur commented on Dec 9, 2019

    @lovelydinosaur
    Member

    Sure thing.

    We shouold probably change this...

    self.headers["Content-Type"] = content_type

    To self.headers.setdefault('Content-Type', content_type), so that if the user has explicitly set a Content-Type header that takes precedence.

    (Or else leave that line as it is an use if content_type and 'Content-Type' not in self.headers in the previous line.)

    Pull requests accepted.

  3. added
    bugSomething isn't working
    and removed
    questionFurther information is requested
    on Dec 9, 2019
  4. changed the title [-]httpx replace Content-Type[/-] [+]Any explicit `Content-Type` header should take precedence over the encoding default.[/+] on Dec 9, 2019
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

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions