https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.9
()
| 240 | |
| 241 | // https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.9 |
| 242 | func (p *parser) parseString() (string, error) { |
| 243 | if p.isEmpty() { |
| 244 | return "", errors.New("structuredheader: string expected, got EOS") |
| 245 | } |
| 246 | if !p.consumeChar('"') { |
| 247 | return "", fmt.Errorf("structuredheader: '\"' expected, got '%c'", p.input[0]) |
| 248 | } |
| 249 | |
| 250 | var b strings.Builder |
| 251 | for !p.isEmpty() { |
| 252 | c := p.getChar() |
| 253 | if c == '\\' { |
| 254 | if p.isEmpty() { |
| 255 | break |
| 256 | } |
| 257 | c = p.getChar() |
| 258 | if c != '"' && c != '\\' { |
| 259 | return "", fmt.Errorf("structuredheader: invalid escape \\%c", c) |
| 260 | } |
| 261 | b.WriteByte(c) |
| 262 | } else if c == '"' { |
| 263 | return b.String(), nil |
| 264 | } else if c < ' ' || c > '~' { |
| 265 | return "", fmt.Errorf("structuredheader: invalid character \\x%02x", c) |
| 266 | } else { |
| 267 | b.WriteByte(c) |
| 268 | } |
| 269 | } |
| 270 | return "", errors.New("structuredheader: missing closing '\"'") |
| 271 | } |
| 272 | |
| 273 | // https://tools.ietf.org/html/draft-ietf-httpbis-header-structure-09#section-4.2.10 |
| 274 | func (p *parser) parseToken() (Token, error) { |