validHeaderValueByte reports whether c is a valid byte in a header field value. RFC 7230 says: field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] field-vchar = VCHAR / obs-text obs-text = %x80-FF RFC 5234 says: HTAB = %x09 SP = %x20 VCHAR
(c byte)
| 439 | // SP = %x20 |
| 440 | // VCHAR = %x21-7E |
| 441 | func validHeaderValueByte(c byte) bool { |
| 442 | // mask is a 128-bit bitmap with 1s for allowed bytes, |
| 443 | // so that the byte c can be tested with a shift and an and. |
| 444 | // If c >= 128, then 1<<c and 1<<(c-64) will both be zero. |
| 445 | // Since this is the obs-text range, we invert the mask to |
| 446 | // create a bitmap with 1s for disallowed bytes. |
| 447 | const mask = 0 | |
| 448 | (1<<(0x7f-0x21)-1)<<0x21 | // VCHAR: %x21-7E |
| 449 | 1<<0x20 | // SP: %x20 |
| 450 | 1<<0x09 // HTAB: %x09 |
| 451 | return ((uint64(1)<<c)&^(mask&(1<<64-1)) | |
| 452 | (uint64(1)<<(c-64))&^(mask>>64)) == 0 |
| 453 | } |
| 454 | |
| 455 | // commonHeader interns common header strings. |
| 456 | var commonHeader map[string]string |
no outgoing calls
no test coverage detected
searching dependent graphs…