#33230: Test client doesn't set explicitly provided Content-Type when data is 
empty
-------------------------------------+-------------------------------------
     Reporter:  Markus Holtermann    |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Testing framework    |                  Version:  3.2
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Anders Kaseorg):

 * status:  closed => new
 * resolution:  wontfix =>


Comment:

 Reopening with two arguments, one theoretical and one practical.

 The test client currently omits both `Content-Length` and `Content-Type`
 for an empty `PATCH`/`POST`/`PUT` body. But RFC 9110 is [https://www.rfc-
 editor.org/rfc/rfc9110#section-8.6-5 explicitly clear] that `Content-
 Length` is expected here: “A user agent SHOULD send Content-Length in a
 request when the method defines a meaning for enclosed content and it is
 not sending Transfer-Encoding. For example, a user agent normally sends
 Content-Length in a POST request even when the value is 0 (indicating
 empty content). A user agent SHOULD NOT send a Content-Length header field
 when the request message does not contain content and the method semantics
 do not anticipate such data.”

 Although the expectation for `Content-Type` is potentially more open to
 interpretation (“A sender that generates a message containing content
 SHOULD generate a Content-Type header field…”), including it is the only
 way to inform the server how to decode the empty body; for example, an
 empty `application/x-www-form-urlencoded` body is valid while an empty
 `application/json` body is not.

 As a practical application, this is required for validating requests
 against an OpenAPI document: the `Content-Type` is needed to
 [https://spec.openapis.org/oas/v3.1.0#requestBodyObject index into the
 map] that declares the body’s schema and encoding.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33230#comment:4>
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/0107018b5af99386-3eda4133-02b2-47f5-9c2a-97e7ccfb5f0d-000000%40eu-central-1.amazonses.com.

Reply via email to