When Prefer: return=minimal is used, rest-layer will return empty body with HTTP code of 204,
however this results in a bogus log line with following text:
Can't send response: http: request method or response status code does not allow body
Mental trace of the issue:
func itemPatch executes this statements:
status = 200
if isNoContent(r) {
item.Payload = nil
status = 204
}
thus making item.Payload = nil
However later down the pipeline in func FormatItem(...)(ctx context, body interface{}) we have:
If skipBody is not flagged, we are returning map[string]interface{}{nil} which is not the same as interface{}{nil}.
Then later we have func (s DefaultResponseSender) Send(...)
Which checks the body iterface{}, and it is not nil but map[string]interface{}{nil}, so it proceeds with marshaling it to null string. Then on the w.Write().
But since Go's http package doesn't like we just wrote w.WriteHeader(status) of 204, it fails on that w.Write call with the error string Can't send response: http: request method or response status code does not allow body.
When
Prefer: return=minimal
is used,rest-layer
will return empty body with HTTP code of 204, however this results in a bogus log line with following text:Mental trace of the issue:
func itemPatch
executes this statements:thus making
item.Payload = nil
However later down the pipeline infunc FormatItem(...)(ctx context, body interface{})
we have:If
skipBody
is not flagged, we are returningmap[string]interface{}{nil}
which is not the same asinterface{}{nil}
. Then later we havefunc (s DefaultResponseSender) Send(...)
Which checks the
body iterface{}
, and it is notnil
butmap[string]interface{}{nil}
, so it proceeds with marshaling it tonull
string. Then on thew.Write()
. But since Go's http package doesn't like we just wrotew.WriteHeader(status)
of204
, it fails on thatw.Write
call with the error stringCan't send response: http: request method or response status code does not allow body
.Will make a PR shortly.