MCPcopy
hub / github.com/kopia/kopia / GRPCRouterHandler

Method GRPCRouterHandler

internal/server/grpc_session.go:639–659  ·  view source on GitHub ↗

GRPCRouterHandler returns HTTP handler that supports GRPC services and routes non-GRPC calls to the provided handler.

(handler http.Handler)

Source from the content-addressed store, hash-verified

637// GRPCRouterHandler returns HTTP handler that supports GRPC services and
638// routes non-GRPC calls to the provided handler.
639func (s *Server) GRPCRouterHandler(handler http.Handler) http.Handler {
640 s.grpcMutex.Lock()
641 defer s.grpcMutex.Unlock()
642
643 if s.grpcServer == nil {
644 s.grpcServer = grpc.NewServer(
645 grpc.MaxSendMsgSize(repo.MaxGRPCMessageSize),
646 grpc.MaxRecvMsgSize(repo.MaxGRPCMessageSize),
647 )
648
649 s.RegisterGRPCHandlers(s.grpcServer)
650 }
651
652 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
653 if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
654 s.grpcServer.ServeHTTP(w, r)
655 } else {
656 handler.ServeHTTP(w, r)
657 }
658 })
659}
660
661// ShutdownGRPCServer shuts down the GRPC server.
662// Note: Since the GRPC server runs over HTTP handler transport,

Callers 2

runMethod · 0.80
StartServerContextFunction · 0.80

Calls 6

RegisterGRPCHandlersMethod · 0.95
ServeHTTPMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
GetMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected