[http.upgrade.request.private] clean 'parseHeader()' with using [internal.http.request.parser.reqline]

This commit is contained in:
xdrm-brackets 2018-04-25 09:58:50 +02:00
parent 3f5dee7818
commit b3ccc911ee
1 changed files with 3 additions and 30 deletions

View File

@ -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), ": ")