WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.
(code int)
| 47 | // WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly |
| 48 | // used to send error codes. |
| 49 | func (r *Response) WriteHeader(code int) { |
| 50 | if r.Committed { |
| 51 | r.logger.Error("echo: response already written to client") |
| 52 | return |
| 53 | } |
| 54 | r.Status = code |
| 55 | for _, fn := range r.beforeFuncs { |
| 56 | fn() |
| 57 | } |
| 58 | r.ResponseWriter.WriteHeader(r.Status) |
| 59 | r.Committed = true |
| 60 | } |
| 61 | |
| 62 | // Write writes the data to the connection as part of an HTTP reply. |
| 63 | func (r *Response) Write(b []byte) (n int, err error) { |