Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tmc/grpc-websocket-proxy
A proxy to transparently upgrade grpc-gateway streaming endpoints to use websockets
https://github.com/tmc/grpc-websocket-proxy
grpc grpc-gateway proxy websocket
Last synced: 3 days ago
JSON representation
A proxy to transparently upgrade grpc-gateway streaming endpoints to use websockets
- Host: GitHub
- URL: https://github.com/tmc/grpc-websocket-proxy
- Owner: tmc
- License: mit
- Created: 2016-07-12T19:59:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-04T09:05:19.000Z (over 1 year ago)
- Last Synced: 2024-10-29T15:47:51.359Z (3 months ago)
- Topics: grpc, grpc-gateway, proxy, websocket
- Language: Go
- Homepage:
- Size: 57.6 KB
- Stars: 556
- Watchers: 17
- Forks: 72
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# grpc-websocket-proxy
[![GoDoc](https://godoc.org/github.com/tmc/grpc-websocket-proxy/wsproxy?status.svg)](http://godoc.org/github.com/tmc/grpc-websocket-proxy/wsproxy)
Wrap your grpc-gateway mux with this helper to expose streaming endpoints over websockets.
On the wire this uses newline-delimited json encoding of the messages.
Usage:
```diff
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
if err := echoserver.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *grpcAddr, opts); err != nil {
return err
}
- http.ListenAndServe(*httpAddr, mux)
+ http.ListenAndServe(*httpAddr, wsproxy.WebsocketProxy(mux))
```# wsproxy
import "github.com/tmc/grpc-websocket-proxy/wsproxy"Package wsproxy implements a websocket proxy for grpc-gateway backed services
## Usage
```go
var (
MethodOverrideParam = "method"
TokenCookieName = "token"
)
```#### func WebsocketProxy
```go
func WebsocketProxy(h http.Handler) http.HandlerFunc
```
WebsocketProxy attempts to expose the underlying handler as a bidi websocket
stream with newline-delimited JSON as the content encoding.The HTTP Authorization header is either populated from the
Sec-Websocket-Protocol field or by a cookie. The cookie name is specified by the
TokenCookieName value.example:
Sec-Websocket-Protocol: Bearer, foobar
is converted to:
Authorization: Bearer foobar
Method can be overwritten with the MethodOverrideParam get parameter in the
requested URL