prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Compress requests / responses
  Leverage `gzip` to compress requests / responses.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mlserver/rest/app.py`
  Content:
  ```
  1 from typing import Callable
  2 from fastapi import FastAPI
  3 from fastapi.responses import Response as FastAPIResponse
  4 from fastapi.routing import APIRoute as FastAPIRoute
  5 from fastapi.middleware.cors import CORSMiddleware
  6 from starlette_exporter import PrometheusMiddleware
  7 
  8 from .endpoints import Endpoints, ModelRepositoryEndpoints
  9 from .requests import Request
  10 from .responses import Response
  11 from .errors import _EXCEPTION_HANDLERS
  12 
  13 from ..settings import Settings
  14 from ..handlers import DataPlane, ModelRepositoryHandlers
  15 
  16 
  17 class APIRoute(FastAPIRoute):
  18     """
  19     Custom route to use our own Request handler.
  20     """
  21 
  22     def get_route_handler(self) -> Callable:
  23         original_route_handler = super().get_route_handler()
  24 
  25         async def custom_route_handler(request: Request) -> FastAPIResponse:
  26             request = Request(request.scope, request.receive)
  27             return await original_route_handler(request)
  28 
  29         return custom_route_handler
  30 
  31 
  32 def create_app(
  33     settings: Settings,
  34     data_plane: DataPlane,
  35     model_repository_handlers: ModelRepositoryHandlers,
  36 ) -> FastAPI:
  37     endpoints = Endpoints(data_plane)
  38     model_repository_endpoints = ModelRepositoryEndpoints(model_repository_handlers)
  39 
  40     routes = [
  41         # Model ready
  42         APIRoute(
  43             "/v2/models/{model_name}/ready",
  44             endpoints.model_ready,
  45         ),
  46         APIRoute(
  47             "/v2/models/{model_name}/versions/{model_version}/ready",
  48             endpoints.model_ready,
  49         ),
  50         # Model infer
  51         APIRoute(
  52             "/v2/models/{model_name}/infer",
  53             endpoints.infer,
  54             methods=["POST"],
  55         ),
  56         APIRoute(
  57             "/v2/models/{model_name}/versions/{model_version}/infer",
  58             endpoints.infer,
  59             methods=["POST"],
  60         ),
  61         # Model metadata
  62         APIRoute(
  63             "/v2/models/{model_name}",
  64             endpoints.model_metadata,
  65         ),
  66         APIRoute(
  67             "/v2/models/{model_name}/versions/{model_version}",
  68             endpoints.model_metadata,
  69         ),
  70         # Liveness and readiness
  71         APIRoute("/v2/health/live", endpoints.live),
  72         APIRoute("/v2/health/ready", endpoints.ready),
  73         # Server metadata
  74         APIRoute(
  75             "/v2",
  76             endpoints.metadata,
  77         ),
  78     ]
  79 
  80     routes += [
  81         # Model Repository API
  82         APIRoute(
  83             "/v2/repository/index",
  84             model_repository_endpoints.index,
  85             methods=["POST"],
  86         ),
  87         APIRoute(
  88             "/v2/repository/models/{model_name}/load",
  89             model_repository_endpoints.load,
  90             methods=["POST"],
  91         ),
  92         APIRoute(
  93             "/v2/repository/models/{model_name}/unload",
  94             model_repository_endpoints.unload,
  95             methods=["POST"],
  96         ),
  97     ]
  98 
  99     app = FastAPI(
  100         debug=settings.debug,
  101         routes=routes,  # type: ignore
  102         default_response_class=Response,
  103         exception_handlers=_EXCEPTION_HANDLERS,  # type: ignore
  104     )
  105 
  106     if settings.cors_settings is not None:
  107         app.add_middleware(
  108             CORSMiddleware,
  109             allow_origins=settings.cors_settings.allow_origins,
  110             allow_origin_regex=settings.cors_settings.allow_origin_regex,
  111             allow_credentials=settings.cors_settings.allow_credentials,
  112             allow_methods=settings.cors_settings.allow_methods,
  113             allow_headers=settings.cors_settings.allow_headers,
  114             max_age=settings.cors_settings.max_age,
  115         )
  116 
  117     if settings.metrics_endpoint:
  118         app.add_middleware(
  119             PrometheusMiddleware,
  120             app_name="mlserver",
  121             prefix="rest_server",
  122             # TODO: Should we also exclude model's health endpoints?
  123             skip_paths=[
  124                 settings.metrics_endpoint,
  125                 "/v2/health/live",
  126                 "/v2/health/ready",
  127             ],
  128         )
  129 
  130     return app
  131
  ```
  --- 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/mlserver/rest/app.py b/mlserver/rest/app.py
  --- a/mlserver/rest/app.py
  +++ b/mlserver/rest/app.py
  @@ -3,6 +3,7 @@
   from fastapi.responses import Response as FastAPIResponse
   from fastapi.routing import APIRoute as FastAPIRoute
   from fastapi.middleware.cors import CORSMiddleware
  +from fastapi.middleware.gzip import GZipMiddleware
   from starlette_exporter import PrometheusMiddleware
   
   from .endpoints import Endpoints, ModelRepositoryEndpoints
  @@ -103,6 +104,7 @@
           exception_handlers=_EXCEPTION_HANDLERS,  # type: ignore
       )
   
  +    app.add_middleware(GZipMiddleware)
       if settings.cors_settings is not None:
           app.add_middleware(
               CORSMiddleware,
  
verification_info: {"golden_diff": "diff --git a/mlserver/rest/app.py b/mlserver/rest/app.py\n--- a/mlserver/rest/app.py\n+++ b/mlserver/rest/app.py\n@@ -3,6 +3,7 @@\n from fastapi.responses import Response as FastAPIResponse\n from fastapi.routing import APIRoute as FastAPIRoute\n from fastapi.middleware.cors import CORSMiddleware\n+from fastapi.middleware.gzip import GZipMiddleware\n from starlette_exporter import PrometheusMiddleware\n \n from .endpoints import Endpoints, ModelRepositoryEndpoints\n@@ -103,6 +104,7 @@\n         exception_handlers=_EXCEPTION_HANDLERS,  # type: ignore\n     )\n \n+    app.add_middleware(GZipMiddleware)\n     if settings.cors_settings is not None:\n         app.add_middleware(\n             CORSMiddleware,\n", "issue": "Compress requests / responses\nLeverage `gzip` to compress requests / responses.\n", "before_files": [{"content": "from typing import Callable\nfrom fastapi import FastAPI\nfrom fastapi.responses import Response as FastAPIResponse\nfrom fastapi.routing import APIRoute as FastAPIRoute\nfrom fastapi.middleware.cors import CORSMiddleware\nfrom starlette_exporter import PrometheusMiddleware\n\nfrom .endpoints import Endpoints, ModelRepositoryEndpoints\nfrom .requests import Request\nfrom .responses import Response\nfrom .errors import _EXCEPTION_HANDLERS\n\nfrom ..settings import Settings\nfrom ..handlers import DataPlane, ModelRepositoryHandlers\n\n\nclass APIRoute(FastAPIRoute):\n    \"\"\"\n    Custom route to use our own Request handler.\n    \"\"\"\n\n    def get_route_handler(self) -> Callable:\n        original_route_handler = super().get_route_handler()\n\n        async def custom_route_handler(request: Request) -> FastAPIResponse:\n            request = Request(request.scope, request.receive)\n            return await original_route_handler(request)\n\n        return custom_route_handler\n\n\ndef create_app(\n    settings: Settings,\n    data_plane: DataPlane,\n    model_repository_handlers: ModelRepositoryHandlers,\n) -> FastAPI:\n    endpoints = Endpoints(data_plane)\n    model_repository_endpoints = ModelRepositoryEndpoints(model_repository_handlers)\n\n    routes = [\n        # Model ready\n        APIRoute(\n            \"/v2/models/{model_name}/ready\",\n            endpoints.model_ready,\n        ),\n        APIRoute(\n            \"/v2/models/{model_name}/versions/{model_version}/ready\",\n            endpoints.model_ready,\n        ),\n        # Model infer\n        APIRoute(\n            \"/v2/models/{model_name}/infer\",\n            endpoints.infer,\n            methods=[\"POST\"],\n        ),\n        APIRoute(\n            \"/v2/models/{model_name}/versions/{model_version}/infer\",\n            endpoints.infer,\n            methods=[\"POST\"],\n        ),\n        # Model metadata\n        APIRoute(\n            \"/v2/models/{model_name}\",\n            endpoints.model_metadata,\n        ),\n        APIRoute(\n            \"/v2/models/{model_name}/versions/{model_version}\",\n            endpoints.model_metadata,\n        ),\n        # Liveness and readiness\n        APIRoute(\"/v2/health/live\", endpoints.live),\n        APIRoute(\"/v2/health/ready\", endpoints.ready),\n        # Server metadata\n        APIRoute(\n            \"/v2\",\n            endpoints.metadata,\n        ),\n    ]\n\n    routes += [\n        # Model Repository API\n        APIRoute(\n            \"/v2/repository/index\",\n            model_repository_endpoints.index,\n            methods=[\"POST\"],\n        ),\n        APIRoute(\n            \"/v2/repository/models/{model_name}/load\",\n            model_repository_endpoints.load,\n            methods=[\"POST\"],\n        ),\n        APIRoute(\n            \"/v2/repository/models/{model_name}/unload\",\n            model_repository_endpoints.unload,\n            methods=[\"POST\"],\n        ),\n    ]\n\n    app = FastAPI(\n        debug=settings.debug,\n        routes=routes,  # type: ignore\n        default_response_class=Response,\n        exception_handlers=_EXCEPTION_HANDLERS,  # type: ignore\n    )\n\n    if settings.cors_settings is not None:\n        app.add_middleware(\n            CORSMiddleware,\n            allow_origins=settings.cors_settings.allow_origins,\n            allow_origin_regex=settings.cors_settings.allow_origin_regex,\n            allow_credentials=settings.cors_settings.allow_credentials,\n            allow_methods=settings.cors_settings.allow_methods,\n            allow_headers=settings.cors_settings.allow_headers,\n            max_age=settings.cors_settings.max_age,\n        )\n\n    if settings.metrics_endpoint:\n        app.add_middleware(\n            PrometheusMiddleware,\n            app_name=\"mlserver\",\n            prefix=\"rest_server\",\n            # TODO: Should we also exclude model's health endpoints?\n            skip_paths=[\n                settings.metrics_endpoint,\n                \"/v2/health/live\",\n                \"/v2/health/ready\",\n            ],\n        )\n\n    return app\n", "path": "mlserver/rest/app.py"}], "after_files": [{"content": "from typing import Callable\nfrom fastapi import FastAPI\nfrom fastapi.responses import Response as FastAPIResponse\nfrom fastapi.routing import APIRoute as FastAPIRoute\nfrom fastapi.middleware.cors import CORSMiddleware\nfrom fastapi.middleware.gzip import GZipMiddleware\nfrom starlette_exporter import PrometheusMiddleware\n\nfrom .endpoints import Endpoints, ModelRepositoryEndpoints\nfrom .requests import Request\nfrom .responses import Response\nfrom .errors import _EXCEPTION_HANDLERS\n\nfrom ..settings import Settings\nfrom ..handlers import DataPlane, ModelRepositoryHandlers\n\n\nclass APIRoute(FastAPIRoute):\n    \"\"\"\n    Custom route to use our own Request handler.\n    \"\"\"\n\n    def get_route_handler(self) -> Callable:\n        original_route_handler = super().get_route_handler()\n\n        async def custom_route_handler(request: Request) -> FastAPIResponse:\n            request = Request(request.scope, request.receive)\n            return await original_route_handler(request)\n\n        return custom_route_handler\n\n\ndef create_app(\n    settings: Settings,\n    data_plane: DataPlane,\n    model_repository_handlers: ModelRepositoryHandlers,\n) -> FastAPI:\n    endpoints = Endpoints(data_plane)\n    model_repository_endpoints = ModelRepositoryEndpoints(model_repository_handlers)\n\n    routes = [\n        # Model ready\n        APIRoute(\n            \"/v2/models/{model_name}/ready\",\n            endpoints.model_ready,\n        ),\n        APIRoute(\n            \"/v2/models/{model_name}/versions/{model_version}/ready\",\n            endpoints.model_ready,\n        ),\n        # Model infer\n        APIRoute(\n            \"/v2/models/{model_name}/infer\",\n            endpoints.infer,\n            methods=[\"POST\"],\n        ),\n        APIRoute(\n            \"/v2/models/{model_name}/versions/{model_version}/infer\",\n            endpoints.infer,\n            methods=[\"POST\"],\n        ),\n        # Model metadata\n        APIRoute(\n            \"/v2/models/{model_name}\",\n            endpoints.model_metadata,\n        ),\n        APIRoute(\n            \"/v2/models/{model_name}/versions/{model_version}\",\n            endpoints.model_metadata,\n        ),\n        # Liveness and readiness\n        APIRoute(\"/v2/health/live\", endpoints.live),\n        APIRoute(\"/v2/health/ready\", endpoints.ready),\n        # Server metadata\n        APIRoute(\n            \"/v2\",\n            endpoints.metadata,\n        ),\n    ]\n\n    routes += [\n        # Model Repository API\n        APIRoute(\n            \"/v2/repository/index\",\n            model_repository_endpoints.index,\n            methods=[\"POST\"],\n        ),\n        APIRoute(\n            \"/v2/repository/models/{model_name}/load\",\n            model_repository_endpoints.load,\n            methods=[\"POST\"],\n        ),\n        APIRoute(\n            \"/v2/repository/models/{model_name}/unload\",\n            model_repository_endpoints.unload,\n            methods=[\"POST\"],\n        ),\n    ]\n\n    app = FastAPI(\n        debug=settings.debug,\n        routes=routes,  # type: ignore\n        default_response_class=Response,\n        exception_handlers=_EXCEPTION_HANDLERS,  # type: ignore\n    )\n\n    app.add_middleware(GZipMiddleware)\n    if settings.cors_settings is not None:\n        app.add_middleware(\n            CORSMiddleware,\n            allow_origins=settings.cors_settings.allow_origins,\n            allow_origin_regex=settings.cors_settings.allow_origin_regex,\n            allow_credentials=settings.cors_settings.allow_credentials,\n            allow_methods=settings.cors_settings.allow_methods,\n            allow_headers=settings.cors_settings.allow_headers,\n            max_age=settings.cors_settings.max_age,\n        )\n\n    if settings.metrics_endpoint:\n        app.add_middleware(\n            PrometheusMiddleware,\n            app_name=\"mlserver\",\n            prefix=\"rest_server\",\n            # TODO: Should we also exclude model's health endpoints?\n            skip_paths=[\n                settings.metrics_endpoint,\n                \"/v2/health/live\",\n                \"/v2/health/ready\",\n            ],\n        )\n\n    return app\n", "path": "mlserver/rest/app.py"}]}