#36081: HttpResponse 204 (No Content) causes client code to hang if data is
present.
-------------------------------------+-------------------------------------
     Reporter:  Cleophus Robinson    |                     Type:
                                     |  Uncategorized
       Status:  new                  |                Component:  HTTP
                                     |  handling
      Version:  4.2                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
  204,HTTP,API,Timeout               |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 **What Happened**
 I discovered this when returning "{}" as the body for a 204 status
 response.

 **Explanation**
 When returning an HttpResponse to the client with a status of 204 (no
 content), their system will hang if data is actually sent back in the
 body.
 It does this because it's an invalid response and it breaks the HTTP spec.
 Clients will hang until a valid response is returned from the server.

 https://developer.mozilla.org/en-
 US/docs/Web/HTTP/Status/204#compatibility_notes

 "Although this status code is intended for responses with no body, servers
 may erroneously include data after the headers. This issue is observable
 in persistent connections, where the invalid body may include a distinct
 response to a subsequent request. The HTTP protocol allows browsers to
 handle such responses differently (there is an ongoing discussion
 regarding the specification text in the HTTPWG http-core GitHub
 repository).

 Apple Safari rejects any such data. Google Chrome and Microsoft Edge
 discard up to four invalid bytes preceding a valid response. Firefox
 tolerates over a kilobyte of invalid data preceding a valid response."

 **Examples**
 1. This is observed in Postman and other systems, the response is already
 returned but it's still "Receiving Response". In this case, it will
 timeout after a minute. Browsers may handle it differently.
 2. My webhook made the client code timeout and forced the webhook into a
 retry sequence.

 **Solution**
 I think Django should raise an exception in the HttpResponse class if this
 happens. Browsers take their own approach on what to do in this scenario
 and an opinionated stance may be warranted. It will also save developers
 from bizarre behavior.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36081>
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 visit 
https://groups.google.com/d/msgid/django-updates/010701945123c426-ed7af449-9e83-41e1-92d2-fa8231105abe-000000%40eu-central-1.amazonses.com.

Reply via email to