prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Uvicorn via gunicorn worker doesn't respect `--forwarded-allow-ips`
  I use uvicorn in docker as uvicorn-worker for gunicorn for my fastapi app. My application needs to know the real client IP of each request, so I use proxy-server with the `X-Forwarded-For` header.
  
  Gunicorn has a special option to change proxy-ip to real-ip, so I running gunicorn like this:
  ```
  gunicorn \
    ppm_telegram_bot.api:app \
    --forwarded-allow-ips="*" 
    --worker-class=uvicorn.workers.UvicornWorker \
    --bind=0.0.0.0:$PORT
  ```
  
  Because I'm in a container, my WSGI/ASGI server receives requests not from the localhost, but from the docker network.
  
  But uvicorn-worker doesn't respect gunicorn's `forwarded-allow-ips`, so in `ProxyHeadersMiddleware.trusted_hosts` I receive default `127.0.0.1` and proxy-ip instead of real-ip.
  https://github.com/encode/uvicorn/blob/9d9f8820a8155e36dcb5e4d4023f470e51aa4e03/uvicorn/middleware/proxy_headers.py#L14-L17
  
  It looks like uvicorn-worker can forward this information to config via `config_kwargs`: https://github.com/encode/uvicorn/blob/9d9f8820a8155e36dcb5e4d4023f470e51aa4e03/uvicorn/workers.py#L28-L35
  
  I could do PR with this change, if required 🙌 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `uvicorn/workers.py`
  Content:
  ```
  1 import asyncio
  2 import logging
  3 
  4 from gunicorn.workers.base import Worker
  5 from uvicorn.config import Config
  6 from uvicorn.main import Server
  7 
  8 
  9 class UvicornWorker(Worker):
  10     """
  11     A worker class for Gunicorn that interfaces with an ASGI consumer callable,
  12     rather than a WSGI callable.
  13     """
  14 
  15     CONFIG_KWARGS = {"loop": "uvloop", "http": "httptools"}
  16 
  17     def __init__(self, *args, **kwargs):
  18         super(UvicornWorker, self).__init__(*args, **kwargs)
  19 
  20         logger = logging.getLogger("uvicorn.error")
  21         logger.handlers = self.log.error_log.handlers
  22         logger.setLevel(self.log.error_log.level)
  23 
  24         logger = logging.getLogger("uvicorn.access")
  25         logger.handlers = self.log.access_log.handlers
  26         logger.setLevel(self.log.access_log.level)
  27 
  28         config_kwargs = {
  29             "app": None,
  30             "log_config": None,
  31             "timeout_keep_alive": self.cfg.keepalive,
  32             "timeout_notify": self.timeout,
  33             "callback_notify": self.callback_notify,
  34             "limit_max_requests": self.max_requests,
  35         }
  36 
  37         if self.cfg.is_ssl:
  38             ssl_kwargs = {
  39                 "ssl_keyfile": self.cfg.ssl_options.get("keyfile"),
  40                 "ssl_certfile": self.cfg.ssl_options.get("certfile"),
  41                 "ssl_version": self.cfg.ssl_options.get("ssl_version"),
  42                 "ssl_cert_reqs": self.cfg.ssl_options.get("cert_reqs"),
  43                 "ssl_ca_certs": self.cfg.ssl_options.get("ca_certs"),
  44                 "ssl_ciphers": self.cfg.ssl_options.get("ciphers"),
  45             }
  46             config_kwargs.update(ssl_kwargs)
  47 
  48         if self.cfg.settings["backlog"].value:
  49             config_kwargs["backlog"] = self.cfg.settings["backlog"].value
  50 
  51         config_kwargs.update(self.CONFIG_KWARGS)
  52 
  53         self.config = Config(**config_kwargs)
  54 
  55     def init_process(self):
  56         self.config.setup_event_loop()
  57         super(UvicornWorker, self).init_process()
  58 
  59     def init_signals(self):
  60         pass
  61 
  62     def run(self):
  63         self.config.app = self.wsgi
  64         server = Server(config=self.config)
  65         loop = asyncio.get_event_loop()
  66         loop.run_until_complete(server.serve(sockets=self.sockets))
  67 
  68     async def callback_notify(self):
  69         self.notify()
  70 
  71 
  72 class UvicornH11Worker(UvicornWorker):
  73     CONFIG_KWARGS = {"loop": "asyncio", "http": "h11"}
  74
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/uvicorn/workers.py b/uvicorn/workers.py
  --- a/uvicorn/workers.py
  +++ b/uvicorn/workers.py
  @@ -2,6 +2,7 @@
   import logging
   
   from gunicorn.workers.base import Worker
  +
   from uvicorn.config import Config
   from uvicorn.main import Server
   
  @@ -32,6 +33,7 @@
               "timeout_notify": self.timeout,
               "callback_notify": self.callback_notify,
               "limit_max_requests": self.max_requests,
  +            "forwarded_allow_ips": self.cfg.forwarded_allow_ips,
           }
   
           if self.cfg.is_ssl:
  
verification_info: {"golden_diff": "diff --git a/uvicorn/workers.py b/uvicorn/workers.py\n--- a/uvicorn/workers.py\n+++ b/uvicorn/workers.py\n@@ -2,6 +2,7 @@\n import logging\n \n from gunicorn.workers.base import Worker\n+\n from uvicorn.config import Config\n from uvicorn.main import Server\n \n@@ -32,6 +33,7 @@\n             \"timeout_notify\": self.timeout,\n             \"callback_notify\": self.callback_notify,\n             \"limit_max_requests\": self.max_requests,\n+            \"forwarded_allow_ips\": self.cfg.forwarded_allow_ips,\n         }\n \n         if self.cfg.is_ssl:\n", "issue": "Uvicorn via gunicorn worker doesn't respect `--forwarded-allow-ips`\nI use uvicorn in docker as uvicorn-worker for gunicorn for my fastapi app. My application needs to know the real client IP of each request, so I use proxy-server with the `X-Forwarded-For` header.\r\n\r\nGunicorn has a special option to change proxy-ip to real-ip, so I running gunicorn like this:\r\n```\r\ngunicorn \\\r\n  ppm_telegram_bot.api:app \\\r\n  --forwarded-allow-ips=\"*\" \r\n  --worker-class=uvicorn.workers.UvicornWorker \\\r\n  --bind=0.0.0.0:$PORT\r\n```\r\n\r\nBecause I'm in a container, my WSGI/ASGI server receives requests not from the localhost, but from the docker network.\r\n\r\nBut uvicorn-worker doesn't respect gunicorn's `forwarded-allow-ips`, so in `ProxyHeadersMiddleware.trusted_hosts` I receive default `127.0.0.1` and proxy-ip instead of real-ip.\r\nhttps://github.com/encode/uvicorn/blob/9d9f8820a8155e36dcb5e4d4023f470e51aa4e03/uvicorn/middleware/proxy_headers.py#L14-L17\r\n\r\nIt looks like uvicorn-worker can forward this information to config via `config_kwargs`: https://github.com/encode/uvicorn/blob/9d9f8820a8155e36dcb5e4d4023f470e51aa4e03/uvicorn/workers.py#L28-L35\r\n\r\nI could do PR with this change, if required \ud83d\ude4c \n", "before_files": [{"content": "import asyncio\nimport logging\n\nfrom gunicorn.workers.base import Worker\nfrom uvicorn.config import Config\nfrom uvicorn.main import Server\n\n\nclass UvicornWorker(Worker):\n    \"\"\"\n    A worker class for Gunicorn that interfaces with an ASGI consumer callable,\n    rather than a WSGI callable.\n    \"\"\"\n\n    CONFIG_KWARGS = {\"loop\": \"uvloop\", \"http\": \"httptools\"}\n\n    def __init__(self, *args, **kwargs):\n        super(UvicornWorker, self).__init__(*args, **kwargs)\n\n        logger = logging.getLogger(\"uvicorn.error\")\n        logger.handlers = self.log.error_log.handlers\n        logger.setLevel(self.log.error_log.level)\n\n        logger = logging.getLogger(\"uvicorn.access\")\n        logger.handlers = self.log.access_log.handlers\n        logger.setLevel(self.log.access_log.level)\n\n        config_kwargs = {\n            \"app\": None,\n            \"log_config\": None,\n            \"timeout_keep_alive\": self.cfg.keepalive,\n            \"timeout_notify\": self.timeout,\n            \"callback_notify\": self.callback_notify,\n            \"limit_max_requests\": self.max_requests,\n        }\n\n        if self.cfg.is_ssl:\n            ssl_kwargs = {\n                \"ssl_keyfile\": self.cfg.ssl_options.get(\"keyfile\"),\n                \"ssl_certfile\": self.cfg.ssl_options.get(\"certfile\"),\n                \"ssl_version\": self.cfg.ssl_options.get(\"ssl_version\"),\n                \"ssl_cert_reqs\": self.cfg.ssl_options.get(\"cert_reqs\"),\n                \"ssl_ca_certs\": self.cfg.ssl_options.get(\"ca_certs\"),\n                \"ssl_ciphers\": self.cfg.ssl_options.get(\"ciphers\"),\n            }\n            config_kwargs.update(ssl_kwargs)\n\n        if self.cfg.settings[\"backlog\"].value:\n            config_kwargs[\"backlog\"] = self.cfg.settings[\"backlog\"].value\n\n        config_kwargs.update(self.CONFIG_KWARGS)\n\n        self.config = Config(**config_kwargs)\n\n    def init_process(self):\n        self.config.setup_event_loop()\n        super(UvicornWorker, self).init_process()\n\n    def init_signals(self):\n        pass\n\n    def run(self):\n        self.config.app = self.wsgi\n        server = Server(config=self.config)\n        loop = asyncio.get_event_loop()\n        loop.run_until_complete(server.serve(sockets=self.sockets))\n\n    async def callback_notify(self):\n        self.notify()\n\n\nclass UvicornH11Worker(UvicornWorker):\n    CONFIG_KWARGS = {\"loop\": \"asyncio\", \"http\": \"h11\"}\n", "path": "uvicorn/workers.py"}], "after_files": [{"content": "import asyncio\nimport logging\n\nfrom gunicorn.workers.base import Worker\n\nfrom uvicorn.config import Config\nfrom uvicorn.main import Server\n\n\nclass UvicornWorker(Worker):\n    \"\"\"\n    A worker class for Gunicorn that interfaces with an ASGI consumer callable,\n    rather than a WSGI callable.\n    \"\"\"\n\n    CONFIG_KWARGS = {\"loop\": \"uvloop\", \"http\": \"httptools\"}\n\n    def __init__(self, *args, **kwargs):\n        super(UvicornWorker, self).__init__(*args, **kwargs)\n\n        logger = logging.getLogger(\"uvicorn.error\")\n        logger.handlers = self.log.error_log.handlers\n        logger.setLevel(self.log.error_log.level)\n\n        logger = logging.getLogger(\"uvicorn.access\")\n        logger.handlers = self.log.access_log.handlers\n        logger.setLevel(self.log.access_log.level)\n\n        config_kwargs = {\n            \"app\": None,\n            \"log_config\": None,\n            \"timeout_keep_alive\": self.cfg.keepalive,\n            \"timeout_notify\": self.timeout,\n            \"callback_notify\": self.callback_notify,\n            \"limit_max_requests\": self.max_requests,\n            \"forwarded_allow_ips\": self.cfg.forwarded_allow_ips,\n        }\n\n        if self.cfg.is_ssl:\n            ssl_kwargs = {\n                \"ssl_keyfile\": self.cfg.ssl_options.get(\"keyfile\"),\n                \"ssl_certfile\": self.cfg.ssl_options.get(\"certfile\"),\n                \"ssl_version\": self.cfg.ssl_options.get(\"ssl_version\"),\n                \"ssl_cert_reqs\": self.cfg.ssl_options.get(\"cert_reqs\"),\n                \"ssl_ca_certs\": self.cfg.ssl_options.get(\"ca_certs\"),\n                \"ssl_ciphers\": self.cfg.ssl_options.get(\"ciphers\"),\n            }\n            config_kwargs.update(ssl_kwargs)\n\n        if self.cfg.settings[\"backlog\"].value:\n            config_kwargs[\"backlog\"] = self.cfg.settings[\"backlog\"].value\n\n        config_kwargs.update(self.CONFIG_KWARGS)\n\n        self.config = Config(**config_kwargs)\n\n    def init_process(self):\n        self.config.setup_event_loop()\n        super(UvicornWorker, self).init_process()\n\n    def init_signals(self):\n        pass\n\n    def run(self):\n        self.config.app = self.wsgi\n        server = Server(config=self.config)\n        loop = asyncio.get_event_loop()\n        loop.run_until_complete(server.serve(sockets=self.sockets))\n\n    async def callback_notify(self):\n        self.notify()\n\n\nclass UvicornH11Worker(UvicornWorker):\n    CONFIG_KWARGS = {\"loop\": \"asyncio\", \"http\": \"h11\"}\n", "path": "uvicorn/workers.py"}]}