I have a Django application which must have the following behavior: if a request has no Content-Type
header, it returns an error response.
In order to test this behavior, I need to make an HTTP request without a Content-Type
header.
I am using the Client
class in the django.test
module. This has many methods, including this one:
post(path, data=None, content_type=MULTIPART_CONTENT, follow=False, secure=False, **extra)
Makes a POST request on the provided path and returns a Response object, which is documented below.
[...]
If you provide content_type (e.g.
text/xml
for an XML payload), the contents of data will be sent as-is in the POST request, usingcontent_type
in the HTTPContent-Type
header.If you don’t provide a value for
content_type
, the values in data will be transmitted with a content type ofmultipart/form-data
. In this case, the key-value pairs in data will be encoded as a multipart message and used to create the POST data payload.
The documentation says that a Content-Type
header is always set on the request, irrespective of whether I pass a content_type
argument.
So what other ways do I have to construct a request, such that it does not have a Content-Type
header?
Aucun commentaire:
Enregistrer un commentaire