...
1# grpc-websocket-proxy
2
3[](http://godoc.org/github.com/tmc/grpc-websocket-proxy/wsproxy)
4
5Wrap your grpc-gateway mux with this helper to expose streaming endpoints over websockets.
6
7On the wire this uses newline-delimited json encoding of the messages.
8
9Usage:
10```diff
11 mux := runtime.NewServeMux()
12 opts := []grpc.DialOption{grpc.WithInsecure()}
13 if err := echoserver.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *grpcAddr, opts); err != nil {
14 return err
15 }
16- http.ListenAndServe(*httpAddr, mux)
17+ http.ListenAndServe(*httpAddr, wsproxy.WebsocketProxy(mux))
18```
19
20
21# wsproxy
22 import "github.com/tmc/grpc-websocket-proxy/wsproxy"
23
24Package wsproxy implements a websocket proxy for grpc-gateway backed services
25
26## Usage
27
28```go
29var (
30 MethodOverrideParam = "method"
31 TokenCookieName = "token"
32)
33```
34
35#### func WebsocketProxy
36
37```go
38func WebsocketProxy(h http.Handler) http.HandlerFunc
39```
40WebsocketProxy attempts to expose the underlying handler as a bidi websocket
41stream with newline-delimited JSON as the content encoding.
42
43The HTTP Authorization header is either populated from the
44Sec-Websocket-Protocol field or by a cookie. The cookie name is specified by the
45TokenCookieName value.
46
47example:
48
49 Sec-Websocket-Protocol: Bearer, foobar
50
51is converted to:
52
53 Authorization: Bearer foobar
54
55Method can be overwritten with the MethodOverrideParam get parameter in the
56requested URL
View as plain text