Review Board 1.5.4

Allow setting the Reason Phrase

Updated 1 year, 11 months ago

Marius Danciu Reviewers
334 dchenbecker, dpp, marius, charles, joni, atsuhiko, jorge, naftoli, kris, indrajit, alexb
None LiftWeb-archive
Allow setting the reason phrase by using ResponseWithPhrase. For example:

ResponseWithReason(new XmlResponse(<cities>
  <city name="Boston"/>
  <city name="New York"/>
  <city name="San Francisco"/>
  <city name="Dallas"/>
  <city name="Chicago"/>
  </cities>, 200, "text/xml; charset=utf-8", Nil), "Hi there"))

Note that underthehood we're using HttpServletResponse#setStatus(code, reason) which is DEPRECATED. Personally I see the value in the reason phrase of HTTP protocol BUT servlet API is very poorly designed in this area.

Personally I'm not pushing for this to make it and my reservation is the use of a deprecated servlet API. If you think that using this API is not a biggie I'm fine with that as well.

P.S. The servlet API recommends using sendError to propagate the reason phrase but this will cause the container to send it's own error page or the page mapped in the web.xml in <errorPage> tag. This is fundamentally stupid and a pain for REST API's. Nonetheless REST API's do have quite a few alternatives to propagate server side textual messages such as using custom headers, or in case of a structured response payload (i.e. xml, json etc) the error message could be in the payload for more specialized API's.  
Yes
Posted 1 year, 11 months ago (February 17th, 2010, 9:11 a.m.)
Anyone, any thoughts?
Ship it!
Posted 1 year, 11 months ago (February 17th, 2010, 4:37 p.m.)
Looks good.
Ship it!
Posted 1 year, 11 months ago (February 20th, 2010, 12:18 a.m.)
I think this is a clean way to get some useful functionality and hide the dirty details. If you look at some of the reasons why setStatus was deprecated, maybe you'll feel better :-)

"The method HttpServletResponse.setStatus(int sc, String sm) is deprecated. The method was confusing to developers, who often used it instead of the correct HttpServletResponse.sendError method to send an error code and message back to the client."
  1. Yes I did look at that ... :-)