Skip to content

Commit

Permalink
fix: correct remote address override in wrapper grpc handling
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Trost <[email protected]>
  • Loading branch information
galexrt committed Oct 12, 2024
1 parent 7bc730c commit d74481e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/composables/grpcws/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class GrpcWSTransport implements RpcTransport {
delay: 1150,
},
protocols: ['grpc-websocket-channel'],

onConnected(ws) {
ws.binaryType = 'arraybuffer';
wsInitiated.value = true;
Expand Down
9 changes: 8 additions & 1 deletion pkg/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,14 @@ func NewEngine(p EngineParams) (*gin.Engine, error) {
grpcws.WithWebsocketPingInterval(40*time.Second),
)
ginWrappedGrpc := func(c *gin.Context) {
c.Request.RemoteAddr = c.ClientIP()
if cip := c.ClientIP(); cip != "" {
if strings.Count(cip, ":") > 1 {
c.Request.RemoteAddr = "[" + cip + "]:80"
} else {
c.Request.RemoteAddr = cip + ":80"
}
}

wrapperGrpc.ServeHTTP(c.Writer, c.Request)
}
e.Any("/api/grpc", ginWrappedGrpc)
Expand Down

0 comments on commit d74481e

Please sign in to comment.