diff --git a/http/upgrade/request/private.go b/http/upgrade/request/private.go index ddcb93e..b4d5a1d 100644 --- a/http/upgrade/request/private.go +++ b/http/upgrade/request/private.go @@ -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 + +} \ No newline at end of file