added 'isComplete' to check request completion

This commit is contained in:
xdrm-brackets 2018-04-25 17:21:21 +02:00
parent b3194f53cb
commit 4994d34bc7
1 changed files with 45 additions and 0 deletions

View File

@ -74,3 +74,48 @@ func (r *T) parseHeader(b []byte) error {
return nil return nil
} }
// isComplete returns whether the Upgrade Request
// is complete (no missing required item)
func (r T) isComplete() error {
/* (1) Request-Line */
if !r.first {
return fmt.Errorf("Missing HTTP Request-Line");
}
/* (2) Host */
if len(r.host) == 0 {
return fmt.Errorf("Missing 'Host' header")
}
/* (3) Origin */
if len(r.origin) == 0 {
return fmt.Errorf("Missing 'Origin' header")
}
/* (4) Connection */
if !r.hasConnection {
return fmt.Errorf("Missing 'Connection' header");
}
/* (5) Upgrade */
if !r.hasUpgrade {
return fmt.Errorf("Missing 'Upgrade' header");
}
/* (6) Sec-WebSocket-Version */
if !r.hasVersion {
return fmt.Errorf("Missing 'Sec-WebSocket-Version' header");
}
/* (7) Sec-WebSocket-Key */
if len(r.key) < 1 {
return fmt.Errorf("Missing 'Sec-WebSocket-Key' header");
}
return nil
}