diff --git a/middleware/websockets/websocket.go b/middleware/websockets/websocket.go index 78ac54110..085399f76 100644 --- a/middleware/websockets/websocket.go +++ b/middleware/websockets/websocket.go @@ -51,7 +51,7 @@ func (ws WebSocket) buildEnv(cmd *exec.Cmd) error { `AUTH_TYPE=`, // Not used `CONTENT_LENGTH=`, // Not used `CONTENT_TYPE=`, // Not used - `GATEWAY_INTERFACE=` + gatewayInterface, + `GATEWAY_INTERFACE=` + GatewayInterface, `PATH_INFO=`, // TODO `PATH_TRANSLATED=`, // TODO `QUERY_STRING=` + ws.URL.RawQuery, @@ -66,7 +66,7 @@ func (ws WebSocket) buildEnv(cmd *exec.Cmd) error { `SERVER_NAME=` + serverHost, `SERVER_PORT=` + serverPort, `SERVER_PROTOCOL=` + ws.Proto, - `SERVER_SOFTWARE=` + serverSoftware, + `SERVER_SOFTWARE=` + ServerSoftware, } // Add each HTTP header to the environment as well @@ -80,11 +80,3 @@ func (ws WebSocket) buildEnv(cmd *exec.Cmd) error { return nil } - -const ( - // See CGI spec, 4.1.4 - gatewayInterface = "caddy-CGI/1.1" - - // See CGI spec, 4.1.17 - serverSoftware = "caddy/0.1.0" -) diff --git a/middleware/websockets/websockets.go b/middleware/websockets/websockets.go index 880dd8346..fe71861ea 100644 --- a/middleware/websockets/websockets.go +++ b/middleware/websockets/websockets.go @@ -17,6 +17,7 @@ type ( // websocket middleware generally, like a list of all the // websocket endpoints. WebSockets struct { + // Sockets holds all the web socket endpoint configurations Sockets []WSConfig } @@ -47,11 +48,8 @@ func (ws WebSockets) ServeHTTP(w http.ResponseWriter, r *http.Request) { func New(c middleware.Controller) (middleware.Middleware, error) { var websocks []WSConfig - var path string - var command string - for c.Next() { - var val string + var val, path, command string // Path or command; not sure which yet if !c.NextArg() { @@ -94,9 +92,25 @@ func New(c middleware.Controller) (middleware.Middleware, error) { }) } + GatewayInterface = envGatewayInterface + ServerSoftware = envServerSoftware + return func(next http.HandlerFunc) http.HandlerFunc { // We don't use next because websockets aren't HTTP, // so we don't invoke other middleware after this. return WebSockets{Sockets: websocks}.ServeHTTP }, nil } + +var ( + // See CGI spec, 4.1.4 + GatewayInterface string + + // See CGI spec, 4.1.17 + ServerSoftware string +) + +const ( + envGatewayInterface = "caddy-CGI/1.1" + envServerSoftware = "caddy/0.1.0" +)