[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 package header
import ( import (
"regexp" // "regexp"
"fmt" "fmt"
"strings" "strings"
"bytes" "bytes"
@ -33,18 +33,8 @@ func Parse(b []byte) (*T, error) {
default: inst.Name = UNKNOWN default: inst.Name = UNKNOWN
} }
/* (4) Check format */ /* (4) Split values */
checker := regexp.MustCompile(`^(?:[^,]+,\s*)*[^,]+$`) inst.Values = bytes.Split(parts[1], []byte(", "))
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(","))
return inst, nil return inst, nil