[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 (
|
||||
"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
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Split by ': ' */
|
||||
parts := strings.Split(string(b), ": ")
|
||||
|
||||
/* (2) Abort on failure */
|
||||
if len(parts) != 2 {
|
||||
/* (1) Try to parse header */
|
||||
head, err := header.Parse(b)
|
||||
if err != nil {
|
||||
r.Err = fmt.Errorf("Error parsing header: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
/* (3) Match header */
|
||||
switch strings.ToLower(parts[0]) {
|
||||
case "host": fmt.Printf("[host] '%s'\n", parts[1])
|
||||
case "upgrade": fmt.Printf("[upgrade] '%s'\n", parts[1])
|
||||
case "connection": fmt.Printf("[connection] '%s'\n", parts[1])
|
||||
case "sec-websocket-key": fmt.Printf("[sec-websocket-key] '%s'\n", parts[1])
|
||||
case "origin": fmt.Printf("[origin] '%s'\n", parts[1])
|
||||
case "sec-websocket-protocol": fmt.Printf("[sec-websocket-protocol] '%s'\n", parts[1])
|
||||
case "sec-websocket-version": fmt.Printf("[sec-websocket-version] '%s'\n", parts[1])
|
||||
/* (2) Manage header */
|
||||
switch head.Name {
|
||||
case header.HOST: fmt.Printf("[host] "); printValues(head.Values)
|
||||
case header.UPGRADE: fmt.Printf("[upgrade] "); printValues(head.Values)
|
||||
case header.CONNECTION: fmt.Printf("[connection] "); printValues(head.Values)
|
||||
case header.WSKEY: fmt.Printf("[sec-websocket-key] "); printValues(head.Values)
|
||||
case header.ORIGIN: fmt.Printf("[origin] "); printValues(head.Values)
|
||||
case header.WSPROTOCOL: fmt.Printf("[sec-websocket-protocol] "); printValues(head.Values)
|
||||
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