GRPCRouterHandler returns HTTP handler that supports GRPC services and routes non-GRPC calls to the provided handler.
(handler http.Handler)
| 637 | // GRPCRouterHandler returns HTTP handler that supports GRPC services and |
| 638 | // routes non-GRPC calls to the provided handler. |
| 639 | func (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, |