| 206 | } |
| 207 | |
| 208 | func checkWriteHeaderCode(code int) { |
| 209 | // Issue 22880: require valid WriteHeader status codes. |
| 210 | // For now we only enforce that it's three digits. |
| 211 | // In the future we might block things over 599 (600 and above aren't defined |
| 212 | // at https://httpwg.org/specs/rfc7231.html#status.codes) |
| 213 | // and we might block under 200 (once we have more mature 1xx support). |
| 214 | // But for now any three digits. |
| 215 | // |
| 216 | // We used to send "HTTP/1.1 000 0" on the wire in responses but there's |
| 217 | // no equivalent bogus thing we can realistically send in HTTP/2, |
| 218 | // so we'll consistently panic instead and help people find their bugs |
| 219 | // early. (We can't return an error from WriteHeader even if we wanted to.) |
| 220 | if code < 100 || code > 999 { |
| 221 | panic(fmt.Sprintf("invalid WriteHeader code %v", code)) |
| 222 | } |
| 223 | } |