发送带有正文的HEAD http请求导致net / http错误

I would like this exception to be caused:

// ErrBodyNotAllowed is returned by ResponseWriter.Write calls
// when the HTTP method or response code does not permit a
// body.
ErrBodyNotAllowed = errors.New("http: request method or response status code does not allow body")

When I send HEAD request with body using fiddler I get 400/504 error codes, but I don't see any error log in my application.

I assume you're talking about a go server that you control. You should see this error returned when you call writer.Write() on a HEAD request. You need to handle it in your application by checking for that error. Find where you are calling Write, and check for the error, then display it to the user. You probably need to replace:

writer.Write(data)

with something like:

_,err := writer.Write(data)