WriterError is a helper that closes over an error that may be returned after writing a response body starts. The normal error flow can't be used, because the HTTP status code will have been sent and some amount of body data may have been written. To use this, make sure an error variable is predecl
(w http.ResponseWriter, e *error)
| 151 | // defer writerError(w, &err)() |
| 152 | // _, err = fallibleWrite(w) |
| 153 | func writerError(w http.ResponseWriter, e *error) func() { |
| 154 | const errHeader = `Clair-Error` |
| 155 | w.Header().Add("trailer", errHeader) |
| 156 | return func() { |
| 157 | if *e == nil { |
| 158 | return |
| 159 | } |
| 160 | w.Header().Add(errHeader, (*e).Error()) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // SetCacheControl sets the "Cache-Control" header on the response. |
| 165 | func setCacheControl(w http.ResponseWriter, age time.Duration) { |
no test coverage detected