7
7
// This file deals with lexical matters of HTTP
9
func isSeparator(c byte) bool {
11
case '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', '\t':
17
func isCtl(c byte) bool { return (0 <= c && c <= 31) || c == 127 }
19
func isChar(c byte) bool { return 0 <= c && c <= 127 }
21
func isAnyText(c byte) bool { return !isCtl(c) }
23
func isQdText(c byte) bool { return isAnyText(c) && c != '"' }
25
func isToken(c byte) bool { return isChar(c) && !isCtl(c) && !isSeparator(c) }
27
// Valid escaped sequences are not specified in RFC 2616, so for now, we assume
28
// that they coincide with the common sense ones used by GO. Malformed
29
// characters should probably not be treated as errors by a robust (forgiving)
30
// parser, so we replace them with the '?' character.
31
func httpUnquotePair(b byte) byte {
32
// skip the first byte, which should always be '\'
58
// raw must begin with a valid quoted string. Only the first quoted string is
59
// parsed and is unquoted in result. eaten is the number of bytes parsed, or -1
61
func httpUnquote(raw []byte) (eaten int, result string) {
62
buf := make([]byte, len(raw))
67
j := 0 // # of bytes written in buf
68
for i := 1; i < len(raw); i++ {
69
switch b := raw[i]; b {
73
return i + 1, string(buf)
78
buf[j] = httpUnquotePair(raw[i+1])
95
// This is a best effort parse, so errors are not returned, instead not all of
96
// the input string might be parsed. result is always non-nil.
97
func httpSplitFieldValue(fv string) (eaten int, result []string) {
98
result = make([]string, 0, len(fv))
106
eaten, unq := httpUnquote(raw[i:len(raw)])
115
result = result[0 : len(result)+1]
116
result[len(result)-1] = chunk
123
case b == '\n' || b == '\r':
131
result = result[0 : len(result)+1]
132
result[len(result)-1] = chunk
9
var isTokenTable = [127]bool{
89
func isToken(r rune) bool {
91
return i < len(isTokenTable) && isTokenTable[i]
94
func isNotToken(r rune) bool {