Use gorilla readMessage and writeMessage instead of just an io.Copy
This commit is contained in:
parent
e8e8b41eed
commit
52f16e11a8
3 changed files with 21 additions and 14 deletions
2
glide.lock
generated
2
glide.lock
generated
|
@ -481,7 +481,7 @@ imports:
|
|||
- name: github.com/urfave/negroni
|
||||
version: 490e6a555d47ca891a89a150d0c1ef3922dfffe9
|
||||
- name: github.com/vulcand/oxy
|
||||
version: 7e9763c4dc71b9758379da3581e6495c145caaab
|
||||
version: bf0e6bab094f7b909a8d94ba9d7b74aaf7cc3025
|
||||
repo: https://github.com/containous/oxy.git
|
||||
vcs: git
|
||||
subpackages:
|
||||
|
|
31
vendor/github.com/vulcand/oxy/forward/fwd.go
generated
vendored
31
vendor/github.com/vulcand/oxy/forward/fwd.go
generated
vendored
|
@ -315,22 +315,29 @@ func (f *websocketForwarder) serveHTTP(w http.ResponseWriter, req *http.Request,
|
|||
defer targetConn.Close()
|
||||
|
||||
errc := make(chan error, 2)
|
||||
replicate := func(dst io.Writer, src io.Reader) {
|
||||
_, err := io.Copy(dst, src)
|
||||
|
||||
replicateWebsocketConn := func(dst, src *websocket.Conn, dstName, srcName string) {
|
||||
var err error
|
||||
for {
|
||||
msgType, msg, err := src.ReadMessage()
|
||||
if err != nil {
|
||||
ctx.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using ReadMessage: %v", srcName, dstName, err)
|
||||
break
|
||||
}
|
||||
err = dst.WriteMessage(msgType, msg)
|
||||
if err != nil {
|
||||
ctx.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using WriteMessage: %v", srcName, dstName, err)
|
||||
break
|
||||
} else {
|
||||
ctx.log.Infof("vulcand/oxy/forward/websocket: Copying from %s to %s completed without error.", srcName, dstName)
|
||||
}
|
||||
}
|
||||
errc <- err
|
||||
}
|
||||
|
||||
go replicate(targetConn.UnderlyingConn(), underlyingConn.UnderlyingConn())
|
||||
go replicateWebsocketConn(underlyingConn, targetConn, "client", "backend")
|
||||
go replicateWebsocketConn(targetConn, underlyingConn, "backend", "client")
|
||||
|
||||
// Try to read the first message
|
||||
t, msg, err := targetConn.ReadMessage()
|
||||
if err != nil {
|
||||
ctx.log.Errorf("Couldn't read first message : %v", err)
|
||||
} else {
|
||||
underlyingConn.WriteMessage(t, msg)
|
||||
}
|
||||
|
||||
go replicate(underlyingConn.UnderlyingConn(), targetConn.UnderlyingConn())
|
||||
<-errc
|
||||
|
||||
}
|
||||
|
|
2
vendor/github.com/vulcand/oxy/utils/netutils.go
generated
vendored
2
vendor/github.com/vulcand/oxy/utils/netutils.go
generated
vendored
|
@ -132,7 +132,7 @@ func RemoveHeaders(headers http.Header, names ...string) {
|
|||
}
|
||||
|
||||
// Parse the MIME media type value of a header.
|
||||
func GetHeaderMediaType(headers http.Header, name string) (string, error) {
|
||||
func GetHeaderMediaType(headers http.Header, name string) (string, error) {
|
||||
mediatype, _, err := mime.ParseMediaType(headers.Get(name))
|
||||
return mediatype, err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue