From e3270318c238416905fd94cf064df661601aca7e Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 25 Apr 2018 15:39:24 +0200 Subject: [PATCH] [internal.http.request.parser.header] optimise: remove 'regexp' + some checks --- internal/http/request/parser/header/public.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/internal/http/request/parser/header/public.go b/internal/http/request/parser/header/public.go index 36be125..c00b6d0 100644 --- a/internal/http/request/parser/header/public.go +++ b/internal/http/request/parser/header/public.go @@ -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