1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

Feature Request: *http.Request access from Websockets. iris.Config.Websocket.IDGenerator custom connection's ID generator added too.

Example:

-
https://github.com/iris-contrib/examples/blob/master/websocket/main.go#L34

Relative commits to kataras/go-websocket:
-
550fc8b32e

-
62c2d989d8
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-01-09 06:23:49 +02:00
parent d5d113b4ca
commit c476fe8921
5 changed files with 131 additions and 25 deletions

View File

@@ -606,10 +606,6 @@ type WebsocketConfiguration struct {
ReadBufferSize int
// WriteBufferSize is the buffer size for the underline writer
WriteBufferSize int
// Headers if true then the client's headers are copy to the websocket connection
//
// Default is true
Headers bool
// Error specifies the function for generating HTTP error responses.
//
// The default behavior is to store the reason in the context (ctx.Set(reason)) and fire any custom error (ctx.EmitError(status))
@@ -621,6 +617,11 @@ type WebsocketConfiguration struct {
// The default behavior is to allow all origins
// you can change this behavior by setting the iris.Config.Websocket.CheckOrigin = iris.WebsocketCheckSameOrigin
CheckOrigin func(r *http.Request) bool
// IDGenerator used to create (and later on, set)
// an ID for each incoming websocket connections (clients).
// If empty then the ID is generated by the result of 64
// random combined characters
IDGenerator func(r *http.Request) string
}
var (
@@ -679,12 +680,7 @@ var (
c.Websocket.WriteBufferSize = val
}
}
// OptionWebsocketHeaders if true then the client's headers are copy to the websocket connection
OptionWebsocketHeaders = func(val bool) OptionSet {
return func(c *Configuration) {
c.Websocket.Headers = val
}
}
// OptionWebsocketError specifies the function for generating HTTP error responses.
OptionWebsocketError = func(val func(*Context, int, error)) OptionSet {
return func(c *Configuration) {
@@ -699,6 +695,16 @@ var (
c.Websocket.CheckOrigin = val
}
}
// OptionWebsocketIDGenerator used to create (and later on, set)
// an ID for each incoming websocket connections (clients).
// If empty then the ID is generated by the result of 64
// random combined characters
OptionWebsocketIDGenerator = func(val func(*http.Request) string) OptionSet {
return func(c *Configuration) {
c.Websocket.IDGenerator = val
}
}
)
const (
@@ -748,7 +754,8 @@ func DefaultWebsocketConfiguration() WebsocketConfiguration {
ReadBufferSize: 4096,
WriteBufferSize: 4096,
Endpoint: "",
Headers: true,
// use the kataras/go-websocket default
IDGenerator: nil,
}
}