#24139: The response reason phrases should evaluate lazily
-------------------------------+--------------------
     Reporter:  jdufresne      |      Owner:  nobody
         Type:  New feature    |     Status:  new
    Component:  HTTP handling  |    Version:  master
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Motivation for this suggestion comes from a bug I found in my own code. I
 traced it back to how Django handles HTTP reason phrases.

 Suggestion:

 If the `status_code` of an HTTP response is set outside of the
 constructor, the `reason_phrase` will be "OK", the default for a 200
 response. The calling code is required to take two steps to successfully
 change the status and reason phrase together.

 {{{
 response = render_to_response(....)
 response.status_code = 503  # Or any status code
 # As of now, reason_phrase is still "OK"
 #
 # Need the line below -- or something like it -- to successfully update
 the reason phrase.
 response.reason_phrase = REASON_PHRASES[response.status_code]
 }}}

 I'm suggesting wrap `reason_phrase` as a property. Internal to the
 response, `reason_phrase` remains `None` unless specified by the calling
 code. Upon accessing `reason_phrase`, if the value is `None` pull from the
 default `REASON_PHRASES` based on the current value of `status_code`.

 I'd also suggest that any change to the `status_code` automatically sets
 `reason_phrase` back to `None` to avoid surprise reason phrases.

 Right now the `reason_phrase` is set once in the constructor and not
 updated based on the latest `status_code`.

 Pull request to follow.

--
Ticket URL: <https://code.djangoproject.com/ticket/24139>
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/052.8fcd63415c7704603aa3f858706ad5d3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to