- Add HTTP/2 transport support for gRPC calls - Implement dispatchGRPC to forward requests to Temporal gRPC server - Replace 501 Not Implemented with actual gRPC proxy - Use golang.org/x/net/http2 for HTTP/2 protocol support - Supports ListWorkflowExecutions and other gRPC methods
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/http2"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
@@ -218,9 +219,33 @@ func (d *Dispatcher) dispatchGRPC(w http.ResponseWriter, r *http.Request, upstre
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
d.writeError(w, problem.NewProblem(http.StatusNotImplemented,
|
// Create HTTP/2 reverse proxy for gRPC
|
||||||
"about:blank#not-implemented", "Not Implemented",
|
// gRPC uses HTTP/2 protocol, so we need an HTTP/2-capable transport
|
||||||
"gRPC forwarding not yet implemented"))
|
upstreamURLObj := &url.URL{
|
||||||
|
Scheme: "http",
|
||||||
|
Host: host,
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy := httputil.NewSingleHostReverseProxy(upstreamURLObj)
|
||||||
|
proxy.Director = func(req *http.Request) {
|
||||||
|
req.URL.Scheme = "http"
|
||||||
|
req.URL.Host = host
|
||||||
|
req.URL.Path = method.UpstreamPath
|
||||||
|
req.RequestURI = ""
|
||||||
|
req.Host = host
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create HTTP/2 client transport for gRPC calls
|
||||||
|
// gRPC requires HTTP/2 for proper message framing
|
||||||
|
h2transport := &http2.Transport{
|
||||||
|
AllowHTTP: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the transport on the proxy
|
||||||
|
proxy.Transport = h2transport
|
||||||
|
|
||||||
|
// Serve the request through the proxy
|
||||||
|
proxy.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dispatcher) writeError(w http.ResponseWriter, p *problem.Problem) {
|
func (d *Dispatcher) writeError(w http.ResponseWriter, p *problem.Problem) {
|
||||||
|
|||||||
Reference in New Issue
Block a user