(code int)
| 119 | } |
| 120 | |
| 121 | func checkWriteHeaderCode(code int) { |
| 122 | // Issue 22880: require valid WriteHeader status codes. |
| 123 | // For now we only enforce that it's three digits. |
| 124 | // In the future we might block things over 599 (600 and above aren't defined |
| 125 | // at https://httpwg.org/specs/rfc7231.html#status.codes) |
| 126 | // and we might block under 200 (once we have more mature 1xx support). |
| 127 | // But for now any three digits. |
| 128 | // |
| 129 | // We used to send "HTTP/1.1 000 0" on the wire in responses but there's |
| 130 | // no equivalent bogus thing we can realistically send in HTTP/2, |
| 131 | // so we'll consistently panic instead and help people find their bugs |
| 132 | // early. (We can't return an error from WriteHeader even if we wanted to.) |
| 133 | if code < 100 || code > 999 { |
| 134 | panic(fmt.Sprintf("invalid WriteHeader code %v", code)) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // WriteHeader implements [http.ResponseWriter]. |
| 139 | func (rw *ResponseRecorder) WriteHeader(code int) { |
no outgoing calls
no test coverage detected
searching dependent graphs…