From b3ccc911ee1c28b0296489d2f7f83925ee61ebb5 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 25 Apr 2018 09:58:50 +0200 Subject: [PATCH] [http.upgrade.request.private] clean 'parseHeader()' with using [internal.http.request.parser.reqline] --- http/upgrade/request/private.go | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/http/upgrade/request/private.go b/http/upgrade/request/private.go index 9c52dfd..4209513 100644 --- a/http/upgrade/request/private.go +++ b/http/upgrade/request/private.go @@ -1,7 +1,6 @@ package request import ( - "strconv" "fmt" "strings" ) @@ -13,48 +12,22 @@ func (r *T) parseHeader(b []byte) { ---------------------------------------------------------*/ if !r.first { - /* (1) Split by ' ' */ - parts := strings.Split(string(b), " ") - - /* (2) Abort on failure */ - if len(parts) != 3 { - return - } - - /* (3) Store method */ - r.httpMethod = parts[0] - - /* (4) Store URI */ - r.uri = parts[1] - - /* (5) Fail if wrong version format */ - if len(parts[2]) < len("HTTP/0") { - r.Err = fmt.Errorf("Invalid HTTP version [%s] expected [HTTP/] prefix") - return - } - - /* (6) Extract version part */ - versionString := parts[2][len("HTTP/"):] - version, err := strconv.ParseFloat(versionString, 32) + err := r.request.Parse(b) if err != nil { - r.Err = fmt.Errorf("Cannot parse HTTP version as float") + r.Err = fmt.Errorf("Error while parsing first line: %s", err) return } - /* (7) Store HTTP version */ - r.httpVersion = float32(version) - - r.first = true return } + /* (2) Other lines -> Header-Name: Header-Value ---------------------------------------------------------*/ - /* (1) Split by ': ' */ parts := strings.Split(string(b), ": ")