From 45a3166dccdf4a41a7ec5fae7b2ae196e8a94649 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 25 Apr 2018 15:41:39 +0200 Subject: [PATCH] [http.upgrade.request] 'parseHeader' directly returns the error (err) --- http/upgrade/request/private.go | 14 ++++++++------ http/upgrade/request/public.go | 8 +++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/http/upgrade/request/private.go b/http/upgrade/request/private.go index 956993e..c9d56f7 100644 --- a/http/upgrade/request/private.go +++ b/http/upgrade/request/private.go @@ -6,7 +6,9 @@ import ( ) -func (r *T) parseHeader(b []byte) { +// parseHeader parses any http request line +// (header and request-line) +func (r *T) parseHeader(b []byte) error { /* (1) First line -> GET {uri} HTTP/{version} ---------------------------------------------------------*/ @@ -15,12 +17,11 @@ func (r *T) parseHeader(b []byte) { err := r.request.Parse(b) if err != nil { - r.Err = fmt.Errorf("Error while parsing first line: %s", err) - return + return fmt.Errorf("Error while parsing first line: %s", err) } r.first = true - return + return nil } @@ -31,8 +32,7 @@ func (r *T) parseHeader(b []byte) { /* (1) Try to parse header */ head, err := header.Parse(b) if err != nil { - r.Err = fmt.Errorf("Error parsing header: %s", err) - return + return fmt.Errorf("Error parsing header: %s", err) } /* (2) Manage header */ @@ -46,6 +46,8 @@ func (r *T) parseHeader(b []byte) { case header.WSVERSION: fmt.Printf("[sec-websocket-version] "); printValues(head.Values) } + return nil + } diff --git a/http/upgrade/request/public.go b/http/upgrade/request/public.go index 83049b7..ec940d9 100644 --- a/http/upgrade/request/public.go +++ b/http/upgrade/request/public.go @@ -31,14 +31,12 @@ func Parse(r io.Reader) (request *T, err error) { return nil, fmt.Errorf("Cannot read from reader: %s", err) } - req.parseHeader(line) + err = req.parseHeader(line) - if req.Err != nil { - return nil, fmt.Errorf("Parsing error: %s\n", req.Err); + if err != nil { + return nil, fmt.Errorf("Parsing error: %s\n", err); } - // fmt.Printf("Read line: %s\n", line) - }