From 9cecf2e0979723a8d8e0bc2fa5eb4569e9500021 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 2 Jan 2020 21:11:25 +0000 Subject: [PATCH] make grpc proxy streaming work --- proxy/mucp/mucp.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 0b059da3..388aba91 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -398,7 +398,7 @@ func (p *Proxy) ServeRequest(ctx context.Context, req server.Request, rsp server // set address if available via routes or specific endpoint if len(routes) > 0 { - addresses := toNodes(routes) + addresses = toNodes(routes) opts = append(opts, client.WithAddress(addresses...)) } @@ -489,6 +489,25 @@ func (p *Proxy) serveRequest(ctx context.Context, link client.Client, service, e } defer stream.Close() + // if we receive a grpc stream we have to refire the initial request + if c, ok := req.Codec().(codec.Codec); ok && c.String() == "grpc" { + // get the header from client + hdr := req.Header() + msg := &codec.Message{ + Type: codec.Request, + Header: hdr, + Body: body, + } + + // write the raw request + err = stream.Request().Codec().Write(msg, nil) + if err == io.EOF { + return nil + } else if err != nil { + return err + } + } + // create client request read loop if streaming go readLoop(req, stream)