added 'String()' to check upgrade request

This commit is contained in:
xdrm-brackets 2018-04-25 17:22:27 +02:00
parent 4df664a138
commit 5649c49837
2 changed files with 14 additions and 1 deletions

View File

@ -57,6 +57,8 @@ func (r *T) parseHeader(b []byte) error {
err = r.extractKey(head.Values) err = r.extractKey(head.Values)
case header.WSPROTOCOL: fmt.Printf("[sec-websocket-protocol] ") case header.WSPROTOCOL: fmt.Printf("[sec-websocket-protocol] ")
err = r.extractProtocols(head.Values)
default: default:
return nil return nil
} }

View File

@ -42,6 +42,13 @@ func Build(r io.Reader) (request *T, err error) {
} }
/* (4) Check completion */
err = req.isComplete()
if err != nil {
return nil, err
}
return req, nil return req, nil
} }
@ -51,6 +58,10 @@ func Build(r io.Reader) (request *T, err error) {
// String returns a textual representation of the upgrade request // String returns a textual representation of the upgrade request
func (r T) String() string{ func (r T) String() string{
return fmt.Sprintf("Upgrade Request\n - host: %s\n - port: %d\n", r.host, r.port) l1 := fmt.Sprintf("Upgrade Request\n - host: %s\n - port: %d\n - origin: %s\n", r.host, r.port, r.origin)
l2 := fmt.Sprintf(" - origin policy: %t\n - connection header: %t\n - upgrade header: %t\n - valid ws version: %t\n", r.validPolicy, r.hasConnection, r.hasUpgrade, r.hasVersion)
l3 := fmt.Sprintf(" - key: %s\n - protocols: %s\n", r.key, r.protocols)
return fmt.Sprintf("%s%s%s", l1, l2, l3)
} }