Setting status reason (reason phrase) for non-standard HTTP status codes

236 views
Skip to first unread message

Frederic Marand

unread,
May 1, 2015, 6:06:03 PM5/1/15
to golan...@googlegroups.com
I have been looking for a way to have custom reasons phrases for non-standard HTTP status codes, and can not find a reasonably clean way of doing it.

Currently, the text for standard responses is defined in net/http/status.go#statusText, exported via the http.StatusText() function, but used directly within the net/http package, to build the status line in the non-exported function net/http/server.go#statusLine() function. This private function is, in turn, used in the private chunkWriter.writeHeader() method.

This has already been a visible problem for the supplementary Golang network libraries : WebDav needs a number of such custom responses, and the authors of the golang.org/x/net/webdav/webdav.go have had to start high up the HTTP stack by reimplementing *Handler.ServerHTTP(), using their own StatusText in that implementation to work around this limitation.

In another approach for the same issu, Camlistore just forcibly writes its custom 207 response for the PROPFIND verb using ResponseWriter.WriteHeader() without setting a reason.

I also found a preceding question on this list https://groups.google.com/forum/#!searchin/golang-nuts/custom$20status/golang-nuts/-6s2HWCbfL4/c1yDX8DfElAJ with no apparent resolution.

Did we all miss something here ? Is there a decision not to support such custom responses ? It seems the custom logic implemented by chunkWriter.writeHeader() is something a non-core program should not have to rewrite for such a simple purpose.

Dave Cheney

unread,
May 1, 2015, 8:05:44 PM5/1/15
to golan...@googlegroups.com
Are you sure about this. WebDAV has additional status codes, but the RFCs do not stipulate the content of this status text.

Frederic Marand

unread,
May 2, 2015, 1:30:51 AM5/2/15
to golan...@googlegroups.com
I was probably not clear : when I mentioned "custom responses", I actually meant "custom status codes" : AIUI he RFC only specifies the status codes, not the text, but they do provide possible reasons in the RFC sample dialogs (e.g. http://tools.ietf.org/html/rfc4918#page-44 ), and the golang webdav implementation has added such reasons, doing it as I described.
Reply all
Reply to author
Forward
0 new messages