[http.upgrade.request] 'parseHeader' directly returns the error (err)

This commit is contained in:
xdrm-brackets 2018-04-25 15:41:39 +02:00
parent e3270318c2
commit 45a3166dcc
2 changed files with 11 additions and 11 deletions

View File

@ -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} /* (1) First line -> GET {uri} HTTP/{version}
---------------------------------------------------------*/ ---------------------------------------------------------*/
@ -15,12 +17,11 @@ func (r *T) parseHeader(b []byte) {
err := r.request.Parse(b) err := r.request.Parse(b)
if err != nil { if err != nil {
r.Err = fmt.Errorf("Error while parsing first line: %s", err) return fmt.Errorf("Error while parsing first line: %s", err)
return
} }
r.first = true r.first = true
return return nil
} }
@ -31,8 +32,7 @@ func (r *T) parseHeader(b []byte) {
/* (1) Try to parse header */ /* (1) Try to parse header */
head, err := header.Parse(b) head, err := header.Parse(b)
if err != nil { if err != nil {
r.Err = fmt.Errorf("Error parsing header: %s", err) return fmt.Errorf("Error parsing header: %s", err)
return
} }
/* (2) Manage header */ /* (2) Manage header */
@ -46,6 +46,8 @@ func (r *T) parseHeader(b []byte) {
case header.WSVERSION: fmt.Printf("[sec-websocket-version] "); printValues(head.Values) case header.WSVERSION: fmt.Printf("[sec-websocket-version] "); printValues(head.Values)
} }
return nil
} }

View File

@ -31,14 +31,12 @@ func Parse(r io.Reader) (request *T, err error) {
return nil, fmt.Errorf("Cannot read from reader: %s", err) return nil, fmt.Errorf("Cannot read from reader: %s", err)
} }
req.parseHeader(line) err = req.parseHeader(line)
if req.Err != nil { if err != nil {
return nil, fmt.Errorf("Parsing error: %s\n", req.Err); return nil, fmt.Errorf("Parsing error: %s\n", err);
} }
// fmt.Printf("Read line: %s\n", line)
} }