#33230: Test client doesn't set explicitly provided Content-Type when data is
empty
---------------------------------------------+------------------------
Reporter: Markus Holtermann | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
When using Django's test client and setting an explicit Content-Type but
have an empty data, the provided content type isn't available in the
request in the view:
{{{#!python
from django.views.decorators.csrf import csrf_exempt
from django.http.response import HttpResponse
@csrf_exempt
def test_view(request):
return HttpResponse(repr(request.headers))
class MyTest(SimpleTestCase):
def test_content_type(self):
resp = self.client.post("/", data=b"", content_type="application
/octet-stream")
print(resp.content)
# b"{'Cookie': ''}"
}}}
Frankly, I'm not sure if that's the intended behavior. Can one set a
Content-Type for a request without payload? The Python Requests library
allows for it and sets the header.
The code in question that only conditionally sets the Content-Type is
https://github.com/django/django/blob/afeafd6036616bac8263d762c1610f22241c0187/django/test/client.py#L461-L466
--
Ticket URL: <https://code.djangoproject.com/ticket/33230>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.9b292115e746dc25010db987e8b961e2%40djangoproject.com.