WriteHeader stores the status to write when the time comes to actually write the header.
(status int)
| 257 | // WriteHeader stores the status to write when the time comes |
| 258 | // to actually write the header. |
| 259 | func (rw *responseWriter) WriteHeader(status int) { |
| 260 | rw.statusCode = status |
| 261 | |
| 262 | // See #5849 and RFC 9110 section 15.4.5 (https://www.rfc-editor.org/rfc/rfc9110.html#section-15.4.5) - 304 |
| 263 | // Not Modified must have certain headers set as if it was a 200 response, and according to the issue |
| 264 | // we would miss the Vary header in this case when compression was also enabled; note that we set this |
| 265 | // header in the responseWriter.init() method but that is only called if we are writing a response body |
| 266 | if status == http.StatusNotModified && !hasVaryValue(rw.Header(), "Accept-Encoding") { |
| 267 | rw.Header().Add("Vary", "Accept-Encoding") |
| 268 | } |
| 269 | |
| 270 | // write status immediately if status is 2xx and the request is CONNECT |
| 271 | // since it means the response is successful. |
| 272 | // see: https://github.com/caddyserver/caddy/issues/6733#issuecomment-2525058845 |
| 273 | if rw.isConnect && 200 <= status && status <= 299 { |
| 274 | rw.ResponseWriter.WriteHeader(status) |
| 275 | rw.wroteHeader = true |
| 276 | } |
| 277 | |
| 278 | // write status immediately when status code is informational |
| 279 | // see: https://caddy.community/t/disappear-103-early-hints-response-with-encode-enable-caddy-v2-7-6/23081/5 |
| 280 | if 100 <= status && status <= 199 { |
| 281 | rw.ResponseWriter.WriteHeader(status) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // Match determines, if encoding should be done based on the ResponseMatcher. |
| 286 | func (enc *Encode) Match(rw *responseWriter) bool { |