prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Wildcard domains and TrustedhostMiddleware
  Support for wildcard domains
  
  </issue>
  <code>
  [start of starlette/middleware/trustedhost.py]
  1 from starlette.datastructures import Headers
  2 from starlette.responses import PlainTextResponse
  3 from starlette.types import ASGIApp, ASGIInstance, Scope
  4 import typing
  5 
  6 
  7 class TrustedHostMiddleware:
  8     def __init__(
  9         self, app: ASGIApp, allowed_hosts: typing.Sequence[str] = ["*"]
  10     ) -> None:
  11         self.app = app
  12         self.allowed_hosts = allowed_hosts
  13         self.allow_any = "*" in allowed_hosts
  14 
  15     def __call__(self, scope: Scope) -> ASGIInstance:
  16         if scope["type"] in ("http", "websocket") and not self.allow_any:
  17             headers = Headers(scope=scope)
  18             host = headers.get("host")
  19             if host not in self.allowed_hosts:
  20                 return PlainTextResponse("Invalid host header", status_code=400)
  21 
  22         return self.app(scope)
  23
  [end of starlette/middleware/trustedhost.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/starlette/middleware/trustedhost.py b/starlette/middleware/trustedhost.py
  --- a/starlette/middleware/trustedhost.py
  +++ b/starlette/middleware/trustedhost.py
  @@ -4,10 +4,17 @@
   import typing
   
   
  +ENFORCE_DOMAIN_WILDCARD = "Domain wildcard patterns must be like '*.example.com'."
  +
  +
   class TrustedHostMiddleware:
       def __init__(
           self, app: ASGIApp, allowed_hosts: typing.Sequence[str] = ["*"]
       ) -> None:
  +        for pattern in allowed_hosts:
  +            assert "*" not in pattern[1:], ENFORCE_DOMAIN_WILDCARD
  +            if pattern.startswith("*") and pattern != "*":
  +                assert pattern.startswith("*."), ENFORCE_DOMAIN_WILDCARD
           self.app = app
           self.allowed_hosts = allowed_hosts
           self.allow_any = "*" in allowed_hosts
  @@ -15,8 +22,15 @@
       def __call__(self, scope: Scope) -> ASGIInstance:
           if scope["type"] in ("http", "websocket") and not self.allow_any:
               headers = Headers(scope=scope)
  -            host = headers.get("host")
  -            if host not in self.allowed_hosts:
  +            host = headers.get("host", "").split(":")[0]
  +            for pattern in self.allowed_hosts:
  +                if (
  +                    host == pattern
  +                    or pattern.startswith("*")
  +                    and host.endswith(pattern[1:])
  +                ):
  +                    break
  +            else:
                   return PlainTextResponse("Invalid host header", status_code=400)
   
           return self.app(scope)
  
verification_info: {"golden_diff": "diff --git a/starlette/middleware/trustedhost.py b/starlette/middleware/trustedhost.py\n--- a/starlette/middleware/trustedhost.py\n+++ b/starlette/middleware/trustedhost.py\n@@ -4,10 +4,17 @@\n import typing\n \n \n+ENFORCE_DOMAIN_WILDCARD = \"Domain wildcard patterns must be like '*.example.com'.\"\n+\n+\n class TrustedHostMiddleware:\n     def __init__(\n         self, app: ASGIApp, allowed_hosts: typing.Sequence[str] = [\"*\"]\n     ) -> None:\n+        for pattern in allowed_hosts:\n+            assert \"*\" not in pattern[1:], ENFORCE_DOMAIN_WILDCARD\n+            if pattern.startswith(\"*\") and pattern != \"*\":\n+                assert pattern.startswith(\"*.\"), ENFORCE_DOMAIN_WILDCARD\n         self.app = app\n         self.allowed_hosts = allowed_hosts\n         self.allow_any = \"*\" in allowed_hosts\n@@ -15,8 +22,15 @@\n     def __call__(self, scope: Scope) -> ASGIInstance:\n         if scope[\"type\"] in (\"http\", \"websocket\") and not self.allow_any:\n             headers = Headers(scope=scope)\n-            host = headers.get(\"host\")\n-            if host not in self.allowed_hosts:\n+            host = headers.get(\"host\", \"\").split(\":\")[0]\n+            for pattern in self.allowed_hosts:\n+                if (\n+                    host == pattern\n+                    or pattern.startswith(\"*\")\n+                    and host.endswith(pattern[1:])\n+                ):\n+                    break\n+            else:\n                 return PlainTextResponse(\"Invalid host header\", status_code=400)\n \n         return self.app(scope)\n", "issue": "Wildcard domains and TrustedhostMiddleware\nSupport for wildcard domains\n", "before_files": [{"content": "from starlette.datastructures import Headers\nfrom starlette.responses import PlainTextResponse\nfrom starlette.types import ASGIApp, ASGIInstance, Scope\nimport typing\n\n\nclass TrustedHostMiddleware:\n    def __init__(\n        self, app: ASGIApp, allowed_hosts: typing.Sequence[str] = [\"*\"]\n    ) -> None:\n        self.app = app\n        self.allowed_hosts = allowed_hosts\n        self.allow_any = \"*\" in allowed_hosts\n\n    def __call__(self, scope: Scope) -> ASGIInstance:\n        if scope[\"type\"] in (\"http\", \"websocket\") and not self.allow_any:\n            headers = Headers(scope=scope)\n            host = headers.get(\"host\")\n            if host not in self.allowed_hosts:\n                return PlainTextResponse(\"Invalid host header\", status_code=400)\n\n        return self.app(scope)\n", "path": "starlette/middleware/trustedhost.py"}]}