package request import ( "fmt" "strings" ) func (r *T) parseHeader(b []byte) { /* (1) First line -> GET {uri} HTTP/{version} ---------------------------------------------------------*/ if !r.first { err := r.request.Parse(b) if err != nil { r.Err = fmt.Errorf("Error while parsing first line: %s", err) return } r.first = true return } /* (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]) } }