Opened 6 years ago

Last modified 6 years ago

#30113 closed Bug

Ignoring body with application/json payload causes HTTP 400 — at Version 1

Reported by: Yoan Mollard Owned by: nobody
Component: HTTP handling Version: 2.1
Severity: Normal Keywords: post, body, json
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Yoan Mollard)

  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()
    
  1. Now send a a first POST with application/json content type, e.g. with axios:
    axios.post("/myview", {"some": "data"})
    
  1. 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.

  1. Now comment out the print function in the view, and see that consuming the payload has fixed the issue

Change History (1)

comment:1 by Yoan Mollard, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top