[http.upgrade.request.private] clean 'parseHeader()' with using [internal.http.request.parser.header]
This commit is contained in:
parent
e375de0f33
commit
8cda08731f
|
@ -2,7 +2,7 @@ package request
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"git.xdrm.io/gws/internal/http/request/parser/header"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,24 +28,39 @@ func (r *T) parseHeader(b []byte) {
|
||||||
|
|
||||||
/* (2) Other lines -> Header-Name: Header-Value
|
/* (2) Other lines -> Header-Name: Header-Value
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
/* (1) Split by ': ' */
|
/* (1) Try to parse header */
|
||||||
parts := strings.Split(string(b), ": ")
|
head, err := header.Parse(b)
|
||||||
|
if err != nil {
|
||||||
/* (2) Abort on failure */
|
r.Err = fmt.Errorf("Error parsing header: %s", err)
|
||||||
if len(parts) != 2 {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (3) Match header */
|
/* (2) Manage header */
|
||||||
switch strings.ToLower(parts[0]) {
|
switch head.Name {
|
||||||
case "host": fmt.Printf("[host] '%s'\n", parts[1])
|
case header.HOST: fmt.Printf("[host] "); printValues(head.Values)
|
||||||
case "upgrade": fmt.Printf("[upgrade] '%s'\n", parts[1])
|
case header.UPGRADE: fmt.Printf("[upgrade] "); printValues(head.Values)
|
||||||
case "connection": fmt.Printf("[connection] '%s'\n", parts[1])
|
case header.CONNECTION: fmt.Printf("[connection] "); printValues(head.Values)
|
||||||
case "sec-websocket-key": fmt.Printf("[sec-websocket-key] '%s'\n", parts[1])
|
case header.WSKEY: fmt.Printf("[sec-websocket-key] "); printValues(head.Values)
|
||||||
case "origin": fmt.Printf("[origin] '%s'\n", parts[1])
|
case header.ORIGIN: fmt.Printf("[origin] "); printValues(head.Values)
|
||||||
case "sec-websocket-protocol": fmt.Printf("[sec-websocket-protocol] '%s'\n", parts[1])
|
case header.WSPROTOCOL: fmt.Printf("[sec-websocket-protocol] "); printValues(head.Values)
|
||||||
case "sec-websocket-version": fmt.Printf("[sec-websocket-version] '%s'\n", parts[1])
|
case header.WSVERSION: fmt.Printf("[sec-websocket-version] "); printValues(head.Values)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func printValues(bb [][]byte){
|
||||||
|
|
||||||
|
for i, b := range bb {
|
||||||
|
|
||||||
|
if i == 0 {
|
||||||
|
fmt.Printf("[ '%s'", b)
|
||||||
|
} else {
|
||||||
|
fmt.Printf(", '%s'", b)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf(" ]\n");
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue