Skip to content

Commit

Permalink
websocket support cross origin requests (easegress-io#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
localvar authored Jun 29, 2023
1 parent c9e16c3 commit 4e47132
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/reference/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,8 @@ The relationship between `methods` and `url` is `AND`.
| clientMaxMsgSize | int | Max client message size, default is 32768. | No |
| loadBalance | [proxy.LoadBalance](#proxyLoadBalanceSpec) | Load balance options | Yes |
| filter | [proxy.RequestMatcherSpec](#proxyrequestmatcherspec) | Filter options for candidate pools | No |
| insecureSkipVerify | bool | Disable origin verification when accepting client connections, default is `false`. | No |
| originPatterns | []string | Host patterns for authorized origins, used to enable cross origin WebSockets. | No |

### mock.Rule

Expand Down
8 changes: 7 additions & 1 deletion pkg/filters/proxies/httpproxy/wspool.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type WebSocketServerPoolSpec struct {
ClientMaxMsgSize int64 `json:"clientMaxMsgSize" jsonschema:"omitempty"`
ServerMaxMsgSize int64 `json:"serverMaxMsgSize" jsonschema:"omitempty"`
Filter *RequestMatcherSpec `json:"filter" jsonschema:"omitempty"`
InsecureSkipVerify bool `json:"insecureSkipVerify" jsonschema:"omitempty"`
OriginPatterns []string `json:"originPatterns" jsonschema:"omitempty"`
}

// NewWebSocketServerPool creates a new server pool according to spec.
Expand Down Expand Up @@ -184,7 +186,11 @@ func (sp *WebSocketServerPool) handle(ctx *context.Context) (result string) {
return resultInternalError
}

clntConn, err := websocket.Accept(stdw, req.Std(), nil)
opts := &websocket.AcceptOptions{
InsecureSkipVerify: sp.spec.InsecureSkipVerify,
OriginPatterns: sp.spec.OriginPatterns,
}
clntConn, err := websocket.Accept(stdw, req.Std(), opts)
if err != nil {
logger.Errorf("%s: failed to establish client connection: %v", sp.Name, err)
sp.buildFailureResponse(ctx, http.StatusBadRequest)
Expand Down

0 comments on commit 4e47132

Please sign in to comment.