[internal.http.request.parser.header] optimise: remove 'regexp' + some checks

This commit is contained in:
xdrm-brackets 2018-04-25 15:39:24 +02:00
parent 1ef8597742
commit e3270318c2
1 changed files with 3 additions and 13 deletions

View File

@ -1,7 +1,7 @@
package header
import (
"regexp"
// "regexp"
"fmt"
"strings"
"bytes"
@ -33,18 +33,8 @@ func Parse(b []byte) (*T, error) {
default: inst.Name = UNKNOWN
}
/* (4) Check format */
checker := regexp.MustCompile(`^(?:[^,]+,\s*)*[^,]+$`)
if !checker.Match(parts[1]) {
return nil, fmt.Errorf("Invalid HTTP header value format '%s'", parts[1]);
}
/* (5) Normalise format */
normaliser := regexp.MustCompile(`,\s+`)
values := normaliser.ReplaceAll(parts[1], []byte(","))
/* (5) Split values */
inst.Values = bytes.Split(values, []byte(","))
/* (4) Split values */
inst.Values = bytes.Split(parts[1], []byte(", "))
return inst, nil