added completion variables to track with asynchronous reading (chunk reader)
This commit is contained in:
parent
4994d34bc7
commit
4df664a138
|
@ -68,18 +68,20 @@ func (r *T) extractOrigin(bb header.HeaderValue) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkOriginPolicy origin policy based on 'host' value
|
// checkOriginPolicy origin policy based on 'host' value
|
||||||
func (r T) checkOriginPolicy() error {
|
func (r *T) checkOriginPolicy() error {
|
||||||
// TODO: Origin policy, for now BYPASS
|
// TODO: Origin policy, for now BYPASS
|
||||||
|
r.validPolicy = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkConnection checks the 'Connection' header
|
// checkConnection checks the 'Connection' header
|
||||||
// it MUST contain 'Upgrade'
|
// it MUST contain 'Upgrade'
|
||||||
func (r T) checkConnection(bb header.HeaderValue) error {
|
func (r *T) checkConnection(bb header.HeaderValue) error {
|
||||||
|
|
||||||
for _, b := range bb {
|
for _, b := range bb {
|
||||||
|
|
||||||
if strings.ToLower( string(b) ) == "upgrade" {
|
if strings.ToLower( string(b) ) == "upgrade" {
|
||||||
|
r.hasConnection = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,13 +93,14 @@ func (r T) checkConnection(bb header.HeaderValue) error {
|
||||||
|
|
||||||
// checkUpgrade checks the 'Upgrade' header
|
// checkUpgrade checks the 'Upgrade' header
|
||||||
// it MUST be 'websocket'
|
// it MUST be 'websocket'
|
||||||
func (r T) checkUpgrade(bb header.HeaderValue) error {
|
func (r *T) checkUpgrade(bb header.HeaderValue) error {
|
||||||
|
|
||||||
if len(bb) != 1 {
|
if len(bb) != 1 {
|
||||||
return fmt.Errorf("Upgrade header must have only 1 element")
|
return fmt.Errorf("Upgrade header must have only 1 element")
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower( string(bb[0]) ) == "websocket" {
|
if strings.ToLower( string(bb[0]) ) == "websocket" {
|
||||||
|
r.hasUpgrade = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,12 +110,13 @@ func (r T) checkUpgrade(bb header.HeaderValue) error {
|
||||||
|
|
||||||
// checkVersion checks the 'Sec-WebSocket-Version' header
|
// checkVersion checks the 'Sec-WebSocket-Version' header
|
||||||
// it MUST be '13'
|
// it MUST be '13'
|
||||||
func (r T) checkVersion(bb header.HeaderValue) error {
|
func (r *T) checkVersion(bb header.HeaderValue) error {
|
||||||
|
|
||||||
if len(bb) != 1 || string(bb[0]) != "13" {
|
if len(bb) != 1 || string(bb[0]) != "13" {
|
||||||
return fmt.Errorf("Sec-WebSocket-Version header must be '13'")
|
return fmt.Errorf("Sec-WebSocket-Version header must be '13'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.hasVersion = true
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -125,6 +129,18 @@ func (r *T) extractKey(bb header.HeaderValue) error {
|
||||||
return fmt.Errorf("Sec-WebSocket-Key header must be a unique 24 bytes base64 value, got %d bytes", len(bb[0]))
|
return fmt.Errorf("Sec-WebSocket-Key header must be a unique 24 bytes base64 value, got %d bytes", len(bb[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.key = bb[0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// extractProtocols extracts the 'Sec-WebSocket-Protocol' header
|
||||||
|
// it can contain multiple values
|
||||||
|
func (r *T) extractProtocols(bb header.HeaderValue) error {
|
||||||
|
|
||||||
|
r.protocols = bb
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
|
@ -13,9 +13,14 @@ type T struct {
|
||||||
host string
|
host string
|
||||||
port uint16 // 0 if not set
|
port uint16 // 0 if not set
|
||||||
origin string
|
origin string
|
||||||
|
validPolicy bool
|
||||||
|
|
||||||
// ws data
|
// ws data
|
||||||
key []byte
|
key []byte
|
||||||
protocols []string
|
protocols [][]byte
|
||||||
version byte
|
|
||||||
|
// required fields check
|
||||||
|
hasConnection bool
|
||||||
|
hasUpgrade bool
|
||||||
|
hasVersion bool
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue