class_docstr: HTTPApp creates a REST API server based on APIs defined with a BentoService
  via BentoService#apis. Each InferenceAPI will become one
  endpoint exposed on the REST server, and the RequestHandler defined on each
  InferenceAPI object will be used to handle Request object before feeding the
  request data into a Service API function
class_docstr_tok: ["HTTPApp","creates","a","REST","API","server","based","on","APIs","defined","with","a","BentoService","via","BentoService","#","apis",".","Each","InferenceAPI","will","become","one","endpoint","exposed","on","the","REST","server",",","and","the","RequestHandler","defined","on","each","InferenceAPI","object","will","be","used","to","handle","Request","object","before","feeding","the","request","data","into","a","Service","API","function"]
code: def middlewares(self) -> list[Middleware]:
      middlewares = super().middlewares
  
      from starlette.middleware import Middleware
  
      for middleware_cls, options in self.bento_service.middlewares:
          middlewares.append(Middleware(middleware_cls, **options))
  
      if self.enable_access_control:
          assert (
              self.access_control_options.get("allow_origins")
              is not None
          ), "To enable cors, access_control_allow_origin must be set"
  
          from starlette.middleware.cors import CORSMiddleware
  
          middlewares.append(
              Middleware(CORSMiddleware, **self.access_control_options)
          )
  
      # metrics middleware
      if self.enable_metrics:
          from .http.instruments import HTTPTrafficMetricsMiddleware
  
          middlewares.append(Middleware(HTTPTrafficMetricsMiddleware))
  
      # otel middleware
      from opentelemetry.instrumentation.asgi import (
          OpenTelemetryMiddleware,
      )
  
      def client_request_hook(span: Span, _: dict[str, t.Any]) -> None:
          if span is not None:
              trace_context.request_id = span.context.span_id
  
      middlewares.append(
          Middleware(
              OpenTelemetryMiddleware,
              excluded_urls=BentoMLContainer.tracing_excluded_urls.get(),
              default_span_details=None,
              server_request_hook=None,
              client_request_hook=client_request_hook,
              tracer_provider=BentoMLContainer.tracer_provider.get(),
          )
      )
  
      access_log_config = (
          BentoMLContainer.api_server_config.logging.access
      )
      if access_log_config.enabled.get():
          from .http.access import AccessLogMiddleware
  
          access_logger = logging.getLogger("bentoml.access")
          if access_logger.getEffectiveLevel() <= logging.INFO:
              middlewares.append(
                  Middleware(
                      AccessLogMiddleware,
                      has_request_content_length=access_log_config.request_content_length.get(),
                      has_request_content_type=access_log_config.request_content_type.get(),
                      has_response_content_length=access_log_config.response_content_length.get(),
                      has_response_content_type=access_log_config.response_content_type.get(),
                  )
              )
  
      return middlewares
  
imports: from __future__ import annotations
  import asyncio
  import functools
  import logging
  import os
  import sys
  import typing
  from simple_di import Provide
  from simple_di import inject
  from starlette.exceptions import HTTPException
  from starlette.responses import PlainTextResponse
  from ...exceptions import BentoMLException
  from ..configuration.containers import BentoMLContainer
  from ..context import trace_context
  from ..server.base_app import BaseAppFactory
  from ..service.service import Service
label_desc: Use image node_id 4 for calling the HTTPAppFactory obj's underlying member method code with example usage: obj.middlewares() and returns: middlewares