[internal.http.request.parser.header] optimise: remove 'regexp' + some checks
This commit is contained in:
parent
1ef8597742
commit
e3270318c2
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue