2018-04-24 21:10:01 +00:00
|
|
|
package request
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (r *T) parseHeader(b []byte) {
|
|
|
|
|
|
|
|
/* (1) First line -> GET {uri} HTTP/{version}
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
if !r.first {
|
|
|
|
|
2018-04-25 07:58:50 +00:00
|
|
|
err := r.request.Parse(b)
|
2018-04-24 21:10:01 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2018-04-25 07:58:50 +00:00
|
|
|
r.Err = fmt.Errorf("Error while parsing first line: %s", err)
|
2018-04-24 21:10:01 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
r.first = true
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-25 07:58:50 +00:00
|
|
|
|
2018-04-24 21:10:01 +00:00
|
|
|
/* (2) Other lines -> Header-Name: Header-Value
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Split by ': ' */
|
|
|
|
parts := strings.Split(string(b), ": ")
|
|
|
|
|
|
|
|
/* (2) Abort on failure */
|
|
|
|
if len(parts) != 2 {
|
|
|
|
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])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|