#30113: Ignoring body with application/json payload causes HTTP 400
-------------------------------------+-------------------------------------
Reporter: ymollard | Owner: nobody
Type: Bug | Status: new
Component: HTTP | Version: 2.1
handling |
Severity: Normal | Keywords: post, body, json
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
1. Create an example view with Django 2.1.4 that does not consume the
request's body:
{{{
@csrf_exempt
def myview(request):
#print(request.body.decode("utf8"))
return HttpResponse()
}}}
2. Now send a a first POST with **application/json** content type, e.g.
with axios:
{{{
axios.post("/myview", {"some": "data"})
}}}
3. Send new identical POST requests, and observe that they cause HTTP 400
errors:
{{{
[17/Jan/2019 22:27:47] "POST /myview HTTP/1.1" 200 0
[17/Jan/2019 22:27:48] "{"some":"data"}POST /myview HTTP/1.1" 200 0
[17/Jan/2019 22:29:44] code 400, message Bad request syntax
('{"some":"data"}')
[17/Jan/2019 22:29:44] "{"some":"data"}" 400 -
}}}
The JSON payload of the first request is still buffered somewhere and mess
up later requests.
4. Now comment out the print function is the view, and see that consuming
the payload has fixed the issue
--
Ticket URL: <https://code.djangoproject.com/ticket/30113>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.3e56268c2e56d8d0656e1f727e94878d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.