code: def cors(allow_headers: Iterable[str]) -> Middleware:
      @middleware
      async def impl(
          request: Request, handler: Handler
      ) -> StreamResponse:
          is_options = request.method == "OPTIONS"
          is_preflight = (
              is_options
              and "Access-Control-Request-Method" in request.headers
          )
          if is_preflight:
              resp = StreamResponse()
          else:
              resp = await handler(request)
  
          origin = request.headers.get("Origin")
          if not origin:
              return resp
  
          resp.headers["Access-Control-Allow-Origin"] = "*"
          resp.headers["Access-Control-Expose-Headers"] = "*"
          if is_options:
              resp.headers["Access-Control-Allow-Headers"] = ", ".join(
                  allow_headers
              )
              resp.headers["Access-Control-Allow-Methods"] = ", ".join(
                  ("OPTIONS", "POST")
              )
  
          return resp
  
      return impl
  
imports: from typing import TYPE_CHECKING, Any, Awaitable, Callable, Iterable, TypeVar
  from aiohttp.web_request import Request
  from aiohttp.web_response import StreamResponse
label_desc: Use image node_id 1 for calling a global function with example usage: cors(allow_headers) and returns: impl, resp, resp