added 'isComplete' to check request completion
This commit is contained in:
parent
b3194f53cb
commit
4994d34bc7
|
@ -74,3 +74,48 @@ func (r *T) parseHeader(b []byte) error {
|
|||
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
|
||||
|
||||
}
|
Loading…
Reference in New Issue