initServers initializes http and grpc servers
(args *PilotArgs)
| 623 | |
| 624 | // initServers initializes http and grpc servers |
| 625 | func (s *Server) initServers(args *PilotArgs) { |
| 626 | s.initGrpcServer(args.KeepaliveOptions) |
| 627 | multiplexGRPC := false |
| 628 | if args.ServerOptions.GRPCAddr != "" { |
| 629 | s.grpcAddress = args.ServerOptions.GRPCAddr |
| 630 | } else { |
| 631 | // This happens only if the GRPC port (15010) is disabled. We will multiplex |
| 632 | // it on the HTTP port. Does not impact the HTTPS gRPC or HTTPS. |
| 633 | log.Infof("multiplexing gRPC on http addr %v", args.ServerOptions.HTTPAddr) |
| 634 | multiplexGRPC = true |
| 635 | } |
| 636 | multiplexHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 637 | // If we detect gRPC, serve using grpcServer |
| 638 | if r.ProtoMajor == 2 && strings.HasPrefix(r.Header.Get("content-type"), "application/grpc") { |
| 639 | s.grpcServer.ServeHTTP(w, r) |
| 640 | return |
| 641 | } |
| 642 | // Otherwise, this is meant for the standard HTTP server |
| 643 | s.httpMux.ServeHTTP(w, r) |
| 644 | }) |
| 645 | s.httpServer = &http.Server{ |
| 646 | Addr: args.ServerOptions.HTTPAddr, |
| 647 | Handler: s.httpMux, |
| 648 | IdleTimeout: 90 * time.Second, // matches http.DefaultTransport keep-alive timeout |
| 649 | ReadTimeout: 30 * time.Second, |
| 650 | } |
| 651 | if multiplexGRPC { |
| 652 | // To allow the gRPC handler to make per-request decision, |
| 653 | // use ReadHeaderTimeout instead of ReadTimeout. |
| 654 | s.httpServer.ReadTimeout = 0 |
| 655 | s.httpServer.ReadHeaderTimeout = 30 * time.Second |
| 656 | s.httpServer.Handler = multiplexHandler |
| 657 | protocols := new(http.Protocols) |
| 658 | protocols.SetHTTP1(true) |
| 659 | protocols.SetUnencryptedHTTP2(true) |
| 660 | s.httpServer.Protocols = protocols |
| 661 | s.httpServer.HTTP2 = &http.HTTP2Config{MaxConcurrentStreams: features.MaxConcurrentStreams} |
| 662 | } |
| 663 | |
| 664 | if args.ServerOptions.MonitoringAddr == "" { |
| 665 | s.monitoringMux = s.httpMux |
| 666 | log.Infof("initializing Istiod admin server multiplexed on httpAddr %v", s.httpServer.Addr) |
| 667 | } else { |
| 668 | log.Info("initializing Istiod admin server") |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | // initIstiodAdminServer initializes monitoring, debug and readiness end points. |
| 673 | func (s *Server) initIstiodAdminServer(args *PilotArgs, whc func() map[string]string) error { |