From 181f07ef26d04063bcc7815d236cf402be8a3641 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Tue, 13 Nov 2018 14:42:23 +0100 Subject: [PATCH] web: avoid proxy to connect to the local gRPC server (#4572) By default the gRPC client of the REST API gateway relies on the HTTP_PROXY variable to connect to the local gRPC server which isn't desired as the server runs in the same process. This change uses a custom dialer that connects directly to the server's address. Signed-off-by: Simon Pasquier --- web/api/v2/api.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/api/v2/api.go b/web/api/v2/api.go index c1fe1de4a..9799875a3 100644 --- a/web/api/v2/api.go +++ b/web/api/v2/api.go @@ -18,6 +18,7 @@ import ( "fmt" "math" "math/rand" + "net" "net/http" "os" "path/filepath" @@ -73,7 +74,13 @@ func (api *API) HTTPHandler(grpcAddr string) (http.Handler, error) { enc := new(protoutil.JSONPb) mux := runtime.NewServeMux(runtime.WithMarshalerOption(enc.ContentType(), enc)) - opts := []grpc.DialOption{grpc.WithInsecure()} + opts := []grpc.DialOption{ + grpc.WithInsecure(), + // Replace the default dialer that connects through proxy when HTTP_PROXY is set. + grpc.WithDialer(func(addr string, _ time.Duration) (net.Conn, error) { + return (&net.Dialer{}).DialContext(ctx, "tcp", addr) + }), + } err := pb.RegisterAdminHandlerFromEndpoint(ctx, mux, grpcAddr, opts) if err != nil {