From 4994d34bc721b89939560625066cde7aa539ca26 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 25 Apr 2018 17:21:21 +0200 Subject: [PATCH] added 'isComplete' to check request completion --- http/upgrade/request/private.go | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) 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