agithub icon indicating copy to clipboard operation
agithub copied to clipboard

POST/PUT/PATCH Requests Override Content-Type Header

Open gizmo385 opened this issue 6 years ago • 1 comments

Currently, the POST, PUT, and PATCH methods automatically set the content-type header of any request (that doesn't explicitly supply content-type in the headers keyword argument) to application/json. This happens even if you provide extra_headers on the ConnectionProperties object that specify the content type.

This means that if you are sending POST/PATCH/PUT requests to a non-JSON API, your requests will be sent with application/json as the content-type without your knowledge. This can be confusing for users and cause needless head scratching.

gizmo385 avatar Apr 16 '19 18:04 gizmo385

Possibly related, but header names should be case-insensitive. If a post is made with headers={"Content-Type": "application/xml"}, the post request checks if "content-type" is in headers and adds "content-type" of "application/json". When _fix_headers is called in the request method, it converts everything to lower case, copies to a temporary dict. The order of this operation cannot be known, so it's not deterministic whether the headers will contain "content-type" of "application/json" or "application/xml".

drice avatar Aug 01 '19 17:08 drice