MCPcopy Create free account
hub / github.com/imroc/req / validHeaderValueByte

Function validHeaderValueByte

textproto_reader.go:441–453  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

439// SP = %x20
440// VCHAR = %x21-7E
441func 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.
456var commonHeader map[string]string

Callers 1

readMIMEHeaderMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…