Use gorilla readMessage and writeMessage instead of just an io.Copy
This commit is contained in:
parent
01e17b6c3e
commit
f30ad20c9b
2 changed files with 19 additions and 20 deletions
2
glide.lock
generated
2
glide.lock
generated
|
@ -520,7 +520,7 @@ imports:
|
||||||
- name: github.com/VividCortex/gohistogram
|
- name: github.com/VividCortex/gohistogram
|
||||||
version: 51564d9861991fb0ad0f531c99ef602d0f9866e6
|
version: 51564d9861991fb0ad0f531c99ef602d0f9866e6
|
||||||
- name: github.com/vulcand/oxy
|
- name: github.com/vulcand/oxy
|
||||||
version: 7b6e758ab449705195df638765c4ca472248908a
|
version: 812cebb8c764f2a78cb806267648b8728b4599ad
|
||||||
repo: https://github.com/containous/oxy.git
|
repo: https://github.com/containous/oxy.git
|
||||||
vcs: git
|
vcs: git
|
||||||
subpackages:
|
subpackages:
|
||||||
|
|
37
vendor/github.com/vulcand/oxy/forward/fwd.go
generated
vendored
37
vendor/github.com/vulcand/oxy/forward/fwd.go
generated
vendored
|
@ -5,7 +5,6 @@ package forward
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
@ -214,7 +213,7 @@ func (f *Forwarder) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
if f.log.Level >= log.DebugLevel {
|
if f.log.Level >= log.DebugLevel {
|
||||||
logEntry := f.log.WithField("Request", utils.DumpHttpRequest(req))
|
logEntry := f.log.WithField("Request", utils.DumpHttpRequest(req))
|
||||||
logEntry.Debug("vulcand/oxy/forward: begin ServeHttp on request")
|
logEntry.Debug("vulcand/oxy/forward: begin ServeHttp on request")
|
||||||
defer logEntry.Debug("vulcand/oxy/forward: competed ServeHttp on request")
|
defer logEntry.Debug("vulcand/oxy/forward: completed ServeHttp on request")
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.stateListener != nil {
|
if f.stateListener != nil {
|
||||||
|
@ -333,27 +332,27 @@ func (f *httpForwarder) serveWebSocket(w http.ResponseWriter, req *http.Request,
|
||||||
defer targetConn.Close()
|
defer targetConn.Close()
|
||||||
|
|
||||||
errc := make(chan error, 2)
|
errc := make(chan error, 2)
|
||||||
replicate := func(dst io.Writer, src io.Reader, dstName string, srcName string) {
|
|
||||||
_, errCopy := io.Copy(dst, src)
|
replicateWebsocketConn := func(dst, src *websocket.Conn, dstName, srcName string) {
|
||||||
if errCopy != nil {
|
var err error
|
||||||
f.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using io.Copy: %v", srcName, dstName, errCopy)
|
for {
|
||||||
} else {
|
msgType, msg, err := src.ReadMessage()
|
||||||
f.log.Infof("vulcand/oxy/forward/websocket: Copying from %s to %s using io.Copy completed without error.", srcName, dstName)
|
if err != nil {
|
||||||
|
f.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 {
|
||||||
|
f.log.Errorf("vulcand/oxy/forward/websocket: Error when copying from %s to %s using WriteMessage: %v", srcName, dstName, err)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
errc <- errCopy
|
errc <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
go replicate(targetConn.UnderlyingConn(), underlyingConn.UnderlyingConn(), "backend", "client")
|
go replicateWebsocketConn(underlyingConn, targetConn, "client", "backend")
|
||||||
|
go replicateWebsocketConn(targetConn, underlyingConn, "backend", "client")
|
||||||
|
|
||||||
// Try to read the first message
|
|
||||||
msgType, msg, err := targetConn.ReadMessage()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("vulcand/oxy/forward/websocket: Couldn't read first message : %v", err)
|
|
||||||
} else {
|
|
||||||
underlyingConn.WriteMessage(msgType, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
go replicate(underlyingConn.UnderlyingConn(), targetConn.UnderlyingConn(), "client", "backend")
|
|
||||||
<-errc
|
<-errc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue