Use CloseNotifier to supress spurious HTTP 400 errors on early disconnect
When a client disconnects without completing a HTTP request, we were attempting to process the partial request, which usually leads to a 400 error. These errors can pollute the logs and make it more difficult to track down real bugs. This change uses CloseNotifier to detect disconnects. In combination with checking Content-Length, we can detect a disconnect before sending the full payload, and avoid logging a 400 error. This logic is only applied to PUT, POST, and PATCH endpoints, as these are the places where disconnects during a request are most likely to happen. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
1788ae4870
commit
6cb5670ba5
4 changed files with 83 additions and 4 deletions
|
@ -110,6 +110,13 @@ func (trw *testResponseWriter) Header() http.Header {
|
|||
return trw.header
|
||||
}
|
||||
|
||||
// CloseNotify is only here to make the testResponseWriter implement the
|
||||
// http.CloseNotifier interface, which WithResponseWriter expects to be
|
||||
// implemented.
|
||||
func (trw *testResponseWriter) CloseNotify() <-chan bool {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (trw *testResponseWriter) Write(p []byte) (n int, err error) {
|
||||
if trw.status == 0 {
|
||||
trw.status = http.StatusOK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue