WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions websocketproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type WebsocketProxy struct {
// Dialer contains options for connecting to the backend WebSocket server.
// If nil, DefaultDialer is used.
Dialer *websocket.Dialer

// ModifyResponse allows modifying the websocket messages bidirectionally
// User assigned function will be called with the request, response and original message,
// and must return the modified message. If nil, the data is transmitted unaltered.
ModifyResponse func(*http.Request, *http.Response, []byte) []byte
}

// ProxyHandler returns a new http.Handler interface that reverse proxies the
Expand Down Expand Up @@ -191,6 +196,11 @@ func (w *WebsocketProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
dst.WriteMessage(websocket.CloseMessage, m)
break
}

if w.ModifyResponse != nil {
msg = w.ModifyResponse(req, resp, msg)
}

err = dst.WriteMessage(msgType, msg)
if err != nil {
errc <- err
Expand Down