embed: support websocket for bi-directional streams

release-3.3
Iwasaki Yudai 2017-10-05 16:07:25 -07:00
parent 867e3da0c4
commit 37eabd770e
1 changed files with 14 additions and 1 deletions

View File

@ -37,6 +37,7 @@ import (
gw "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/soheilhy/cmux"
"github.com/tmc/grpc-websocket-proxy/wsproxy"
"golang.org/x/net/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
@ -214,7 +215,19 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
httpmux.Handle(path, h)
}
httpmux.Handle("/v3alpha/", gwmux)
httpmux.Handle(
"/v3alpha/",
wsproxy.WebsocketProxy(
gwmux,
wsproxy.WithRequestMutator(
// Default to the POST method for streams
func(incoming *http.Request, outgoing *http.Request) *http.Request {
outgoing.Method = "POST"
return outgoing
},
),
),
)
if handler != nil {
httpmux.Handle("/", handler)
}