Add convenience method to check if websockets required (#779)

* Add convenience method to check if websockets required

* Add tests

* Fix up tests for develop branch
This commit is contained in:
David Irvine
2017-01-02 03:05:30 -05:00
committed by Bo-Yi Wu
parent ff17a8dd75
commit ebe3580daf
2 changed files with 32 additions and 0 deletions
+10
View File
@@ -383,6 +383,16 @@ func (c *Context) ContentType() string {
return filterFlags(c.requestHeader("Content-Type"))
}
// IsWebsocket returns true if the request headers indicate that a websocket
// handshake is being initiated by the client.
func (c *Context) IsWebsocket() bool {
if strings.Contains(strings.ToLower(c.requestHeader("Connection")), "upgrade") &&
strings.ToLower(c.requestHeader("Upgrade")) == "websocket" {
return true
}
return false
}
func (c *Context) requestHeader(key string) string {
if values, _ := c.Request.Header[key]; len(values) > 0 {
return values[0]