prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  docs.opnfv.org is 'Not Found.'
  ## Details
  
  The entire documentation site for OPNFV is missing. The most recent builds have succeeded, and as far as I know DNS hasn't changed recently.
  
  * Read the Docs project URL: opnfvdocsdemo.readthedocs.io
  * Build URL (if applicable): https://readthedocs.org/projects/opnfvdocsdemo/builds/
  * Read the Docs username (if applicable):
  
  ## Expected Result
  
  Going to https://docs.opnfv.org/ returns the documentation site.
  
  ## Actual Result
  ```
  curl -i -L https://opnfvdocsdemo.readthedocs.io/
  HTTP/1.1 302 Found
  Content-Type: text/html; charset=utf-8
  Location: http://docs.opnfv.org/en/stable-hunter/
  Server: nginx
  X-Frame-Options: DENY
  x-content-type-options: nosniff
  x-xss-protection: 1; mode=block
  X-Served: Django-Proxito
  X-Deity: web04
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  Date: Wed, 29 Jan 2020 23:13:29 GMT
  Content-Length: 0
  
  HTTP/1.1 301 Moved Permanently
  Server: CloudFront
  Date: Wed, 29 Jan 2020 23:13:29 GMT
  Content-Type: text/html
  Content-Length: 183
  Connection: keep-alive
  Location: https://docs.opnfv.org/en/stable-hunter/
  X-Cache: Redirect from cloudfront
  Via: 1.1 5ab5dc09da67e3ea794ec8a82992cc89.cloudfront.net (CloudFront)
  X-Amz-Cf-Pop: HIO50-C1
  X-Amz-Cf-Id: 0_rJ9aN8nFAFm6M9VPcWPWHa7B8QOaSW1_Y3Llttz31ZTaK03cTaYQ==
  
  HTTP/2 404 
  content-type: text/html; charset=utf-8
  content-length: 10
  server: nginx
  x-frame-options: DENY
  x-content-type-options: nosniff
  x-xss-protection: 1; mode=block
  x-served: Proxito-404
  x-deity: web03
  strict-transport-security: max-age=0
  date: Wed, 29 Jan 2020 23:13:30 GMT
  x-cache: Miss from cloudfront
  via: 1.1 1b0911478686968732f973d6e5e31d11.cloudfront.net (CloudFront)
  x-amz-cf-pop: HIO50-C1
  x-amz-cf-id: sRmKIeU3LyXtKb93316GUwkxqiChktuq227k3nhDcOPqU-78E7JFTA==
  
  Not Found.
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `readthedocs/proxito/middleware.py`
  Content:
  ```
  1 """
  2 Middleware for Proxito.
  3 
  4 This is used to take the request and map the host to the proper project slug.
  5 
  6 Additional processing is done to get the project from the URL in the ``views.py`` as well.
  7 """
  8 import logging
  9 
  10 from django.conf import settings
  11 from django.shortcuts import render
  12 from django.utils.deprecation import MiddlewareMixin
  13 
  14 from readthedocs.projects.models import Domain
  15 
  16 log = logging.getLogger(__name__)  # noqa
  17 
  18 
  19 def map_host_to_project_slug(request):
  20     """
  21     Take the request and map the host to the proper project slug.
  22 
  23     We check, in order:
  24 
  25     * The ``HTTP_X_RTD_SLUG`` host header for explicit Project mapping
  26         - This sets ``request.rtdheader`` True
  27     * The ``PUBLIC_DOMAIN`` where we can use the subdomain as the project name
  28         - This sets ``request.subdomain`` True
  29     * The hostname without port information, which maps to ``Domain`` objects
  30         - This sets ``request.cname`` True
  31     """
  32 
  33     host = request.get_host().lower().split(':')[0]
  34     public_domain = settings.PUBLIC_DOMAIN.lower().split(':')[0]
  35     host_parts = host.split('.')
  36     public_domain_parts = public_domain.split('.')
  37 
  38     project_slug = None
  39 
  40     # Explicit Project slug being passed in
  41     if 'HTTP_X_RTD_SLUG' in request.META:
  42         project_slug = request.META['HTTP_X_RTD_SLUG'].lower()
  43         request.rtdheader = True
  44         log.info('Setting project based on X_RTD_SLUG header: %s' % project_slug)
  45 
  46     elif public_domain in host or host == 'proxito':
  47         # Serve from the PUBLIC_DOMAIN, ensuring it looks like `foo.PUBLIC_DOMAIN`
  48         if public_domain_parts == host_parts[1:]:
  49             project_slug = host_parts[0]
  50             request.subdomain = True
  51             log.debug('Proxito Public Domain: host=%s', host)
  52         else:
  53             # TODO: This can catch some possibly valid domains (docs.readthedocs.io.com) for example
  54             # But these feel like they might be phishing, etc. so let's block them for now.
  55             log.warning('Weird variation on our hostname: host=%s', host)
  56             return render(
  57                 request, 'core/dns-404.html', context={'host': host}, status=400
  58             )
  59 
  60     # Serve CNAMEs
  61     else:
  62         domain = Domain.objects.filter(domain=host).first()
  63         if domain:
  64             project_slug = domain.project.slug
  65             request.cname = True
  66             log.debug('Proxito CNAME: host=%s', host)
  67         else:
  68             # Some person is CNAMEing to us without configuring a domain - 404.
  69             log.debug('CNAME 404: host=%s', host)
  70             return render(
  71                 request, 'core/dns-404.html', context={'host': host}, status=404
  72             )
  73 
  74     log.debug('Proxito Project: slug=%s', project_slug)
  75     return project_slug
  76 
  77 
  78 class ProxitoMiddleware(MiddlewareMixin):
  79 
  80     """The actual middleware we'll be using in prod."""
  81 
  82     def process_request(self, request):  # noqa
  83         if any([not settings.USE_SUBDOMAIN, 'localhost' in request.get_host(),
  84                 'testserver' in request.get_host()]):
  85             log.debug('Not processing Proxito middleware')
  86             return None
  87 
  88         ret = map_host_to_project_slug(request)
  89 
  90         # Handle returning a response
  91         if hasattr(ret, 'status_code'):
  92             return ret
  93 
  94         # Otherwise set the slug on the request
  95         request.host_project_slug = request.slug = ret
  96 
  97         return None
  98
  ```
  --- 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/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py
  --- a/readthedocs/proxito/middleware.py
  +++ b/readthedocs/proxito/middleware.py
  @@ -11,7 +11,7 @@
   from django.shortcuts import render
   from django.utils.deprecation import MiddlewareMixin
   
  -from readthedocs.projects.models import Domain
  +from readthedocs.projects.models import Domain, Project
   
   log = logging.getLogger(__name__)  # noqa
   
  @@ -40,39 +40,38 @@
       # Explicit Project slug being passed in
       if 'HTTP_X_RTD_SLUG' in request.META:
           project_slug = request.META['HTTP_X_RTD_SLUG'].lower()
  -        request.rtdheader = True
  -        log.info('Setting project based on X_RTD_SLUG header: %s' % project_slug)
  +        if Project.objects.filter(slug=project_slug).exists():
  +            request.rtdheader = True
  +            log.info('Setting project based on X_RTD_SLUG header: %s', project_slug)
  +            return project_slug
   
  -    elif public_domain in host or host == 'proxito':
  +    if public_domain in host or host == 'proxito':
           # Serve from the PUBLIC_DOMAIN, ensuring it looks like `foo.PUBLIC_DOMAIN`
           if public_domain_parts == host_parts[1:]:
               project_slug = host_parts[0]
               request.subdomain = True
               log.debug('Proxito Public Domain: host=%s', host)
  -        else:
  -            # TODO: This can catch some possibly valid domains (docs.readthedocs.io.com) for example
  -            # But these feel like they might be phishing, etc. so let's block them for now.
  -            log.warning('Weird variation on our hostname: host=%s', host)
  -            return render(
  -                request, 'core/dns-404.html', context={'host': host}, status=400
  -            )
  +            return project_slug
  +        # TODO: This can catch some possibly valid domains (docs.readthedocs.io.com) for example
  +        # But these feel like they might be phishing, etc. so let's block them for now.
  +        log.warning('Weird variation on our hostname: host=%s', host)
  +        return render(
  +            request, 'core/dns-404.html', context={'host': host}, status=400
  +        )
   
       # Serve CNAMEs
  -    else:
  -        domain = Domain.objects.filter(domain=host).first()
  -        if domain:
  -            project_slug = domain.project.slug
  -            request.cname = True
  -            log.debug('Proxito CNAME: host=%s', host)
  -        else:
  -            # Some person is CNAMEing to us without configuring a domain - 404.
  -            log.debug('CNAME 404: host=%s', host)
  -            return render(
  -                request, 'core/dns-404.html', context={'host': host}, status=404
  -            )
  -
  -    log.debug('Proxito Project: slug=%s', project_slug)
  -    return project_slug
  +    domain = Domain.objects.filter(domain=host).first()
  +    if domain:
  +        project_slug = domain.project.slug
  +        request.cname = True
  +        log.debug('Proxito CNAME: host=%s', host)
  +        return project_slug
  +
  +    # Some person is CNAMEing to us without configuring a domain - 404.
  +    log.debug('CNAME 404: host=%s', host)
  +    return render(
  +        request, 'core/dns-404.html', context={'host': host}, status=404
  +    )
   
   
   class ProxitoMiddleware(MiddlewareMixin):
  @@ -91,6 +90,8 @@
           if hasattr(ret, 'status_code'):
               return ret
   
  +        log.debug('Proxito Project: slug=%s', ret)
  +
           # Otherwise set the slug on the request
           request.host_project_slug = request.slug = ret
  
verification_info: {"golden_diff": "diff --git a/readthedocs/proxito/middleware.py b/readthedocs/proxito/middleware.py\n--- a/readthedocs/proxito/middleware.py\n+++ b/readthedocs/proxito/middleware.py\n@@ -11,7 +11,7 @@\n from django.shortcuts import render\n from django.utils.deprecation import MiddlewareMixin\n \n-from readthedocs.projects.models import Domain\n+from readthedocs.projects.models import Domain, Project\n \n log = logging.getLogger(__name__)  # noqa\n \n@@ -40,39 +40,38 @@\n     # Explicit Project slug being passed in\n     if 'HTTP_X_RTD_SLUG' in request.META:\n         project_slug = request.META['HTTP_X_RTD_SLUG'].lower()\n-        request.rtdheader = True\n-        log.info('Setting project based on X_RTD_SLUG header: %s' % project_slug)\n+        if Project.objects.filter(slug=project_slug).exists():\n+            request.rtdheader = True\n+            log.info('Setting project based on X_RTD_SLUG header: %s', project_slug)\n+            return project_slug\n \n-    elif public_domain in host or host == 'proxito':\n+    if public_domain in host or host == 'proxito':\n         # Serve from the PUBLIC_DOMAIN, ensuring it looks like `foo.PUBLIC_DOMAIN`\n         if public_domain_parts == host_parts[1:]:\n             project_slug = host_parts[0]\n             request.subdomain = True\n             log.debug('Proxito Public Domain: host=%s', host)\n-        else:\n-            # TODO: This can catch some possibly valid domains (docs.readthedocs.io.com) for example\n-            # But these feel like they might be phishing, etc. so let's block them for now.\n-            log.warning('Weird variation on our hostname: host=%s', host)\n-            return render(\n-                request, 'core/dns-404.html', context={'host': host}, status=400\n-            )\n+            return project_slug\n+        # TODO: This can catch some possibly valid domains (docs.readthedocs.io.com) for example\n+        # But these feel like they might be phishing, etc. so let's block them for now.\n+        log.warning('Weird variation on our hostname: host=%s', host)\n+        return render(\n+            request, 'core/dns-404.html', context={'host': host}, status=400\n+        )\n \n     # Serve CNAMEs\n-    else:\n-        domain = Domain.objects.filter(domain=host).first()\n-        if domain:\n-            project_slug = domain.project.slug\n-            request.cname = True\n-            log.debug('Proxito CNAME: host=%s', host)\n-        else:\n-            # Some person is CNAMEing to us without configuring a domain - 404.\n-            log.debug('CNAME 404: host=%s', host)\n-            return render(\n-                request, 'core/dns-404.html', context={'host': host}, status=404\n-            )\n-\n-    log.debug('Proxito Project: slug=%s', project_slug)\n-    return project_slug\n+    domain = Domain.objects.filter(domain=host).first()\n+    if domain:\n+        project_slug = domain.project.slug\n+        request.cname = True\n+        log.debug('Proxito CNAME: host=%s', host)\n+        return project_slug\n+\n+    # Some person is CNAMEing to us without configuring a domain - 404.\n+    log.debug('CNAME 404: host=%s', host)\n+    return render(\n+        request, 'core/dns-404.html', context={'host': host}, status=404\n+    )\n \n \n class ProxitoMiddleware(MiddlewareMixin):\n@@ -91,6 +90,8 @@\n         if hasattr(ret, 'status_code'):\n             return ret\n \n+        log.debug('Proxito Project: slug=%s', ret)\n+\n         # Otherwise set the slug on the request\n         request.host_project_slug = request.slug = ret\n", "issue": "docs.opnfv.org is 'Not Found.'\n## Details\r\n\r\nThe entire documentation site for OPNFV is missing. The most recent builds have succeeded, and as far as I know DNS hasn't changed recently.\r\n\r\n* Read the Docs project URL: opnfvdocsdemo.readthedocs.io\r\n* Build URL (if applicable): https://readthedocs.org/projects/opnfvdocsdemo/builds/\r\n* Read the Docs username (if applicable):\r\n\r\n## Expected Result\r\n\r\nGoing to https://docs.opnfv.org/ returns the documentation site.\r\n\r\n## Actual Result\r\n```\r\ncurl -i -L https://opnfvdocsdemo.readthedocs.io/\r\nHTTP/1.1 302 Found\r\nContent-Type: text/html; charset=utf-8\r\nLocation: http://docs.opnfv.org/en/stable-hunter/\r\nServer: nginx\r\nX-Frame-Options: DENY\r\nx-content-type-options: nosniff\r\nx-xss-protection: 1; mode=block\r\nX-Served: Django-Proxito\r\nX-Deity: web04\r\nStrict-Transport-Security: max-age=31536000; includeSubDomains\r\nDate: Wed, 29 Jan 2020 23:13:29 GMT\r\nContent-Length: 0\r\n\r\nHTTP/1.1 301 Moved Permanently\r\nServer: CloudFront\r\nDate: Wed, 29 Jan 2020 23:13:29 GMT\r\nContent-Type: text/html\r\nContent-Length: 183\r\nConnection: keep-alive\r\nLocation: https://docs.opnfv.org/en/stable-hunter/\r\nX-Cache: Redirect from cloudfront\r\nVia: 1.1 5ab5dc09da67e3ea794ec8a82992cc89.cloudfront.net (CloudFront)\r\nX-Amz-Cf-Pop: HIO50-C1\r\nX-Amz-Cf-Id: 0_rJ9aN8nFAFm6M9VPcWPWHa7B8QOaSW1_Y3Llttz31ZTaK03cTaYQ==\r\n\r\nHTTP/2 404 \r\ncontent-type: text/html; charset=utf-8\r\ncontent-length: 10\r\nserver: nginx\r\nx-frame-options: DENY\r\nx-content-type-options: nosniff\r\nx-xss-protection: 1; mode=block\r\nx-served: Proxito-404\r\nx-deity: web03\r\nstrict-transport-security: max-age=0\r\ndate: Wed, 29 Jan 2020 23:13:30 GMT\r\nx-cache: Miss from cloudfront\r\nvia: 1.1 1b0911478686968732f973d6e5e31d11.cloudfront.net (CloudFront)\r\nx-amz-cf-pop: HIO50-C1\r\nx-amz-cf-id: sRmKIeU3LyXtKb93316GUwkxqiChktuq227k3nhDcOPqU-78E7JFTA==\r\n\r\nNot Found.\r\n```\r\n\n", "before_files": [{"content": "\"\"\"\nMiddleware for Proxito.\n\nThis is used to take the request and map the host to the proper project slug.\n\nAdditional processing is done to get the project from the URL in the ``views.py`` as well.\n\"\"\"\nimport logging\n\nfrom django.conf import settings\nfrom django.shortcuts import render\nfrom django.utils.deprecation import MiddlewareMixin\n\nfrom readthedocs.projects.models import Domain\n\nlog = logging.getLogger(__name__)  # noqa\n\n\ndef map_host_to_project_slug(request):\n    \"\"\"\n    Take the request and map the host to the proper project slug.\n\n    We check, in order:\n\n    * The ``HTTP_X_RTD_SLUG`` host header for explicit Project mapping\n        - This sets ``request.rtdheader`` True\n    * The ``PUBLIC_DOMAIN`` where we can use the subdomain as the project name\n        - This sets ``request.subdomain`` True\n    * The hostname without port information, which maps to ``Domain`` objects\n        - This sets ``request.cname`` True\n    \"\"\"\n\n    host = request.get_host().lower().split(':')[0]\n    public_domain = settings.PUBLIC_DOMAIN.lower().split(':')[0]\n    host_parts = host.split('.')\n    public_domain_parts = public_domain.split('.')\n\n    project_slug = None\n\n    # Explicit Project slug being passed in\n    if 'HTTP_X_RTD_SLUG' in request.META:\n        project_slug = request.META['HTTP_X_RTD_SLUG'].lower()\n        request.rtdheader = True\n        log.info('Setting project based on X_RTD_SLUG header: %s' % project_slug)\n\n    elif public_domain in host or host == 'proxito':\n        # Serve from the PUBLIC_DOMAIN, ensuring it looks like `foo.PUBLIC_DOMAIN`\n        if public_domain_parts == host_parts[1:]:\n            project_slug = host_parts[0]\n            request.subdomain = True\n            log.debug('Proxito Public Domain: host=%s', host)\n        else:\n            # TODO: This can catch some possibly valid domains (docs.readthedocs.io.com) for example\n            # But these feel like they might be phishing, etc. so let's block them for now.\n            log.warning('Weird variation on our hostname: host=%s', host)\n            return render(\n                request, 'core/dns-404.html', context={'host': host}, status=400\n            )\n\n    # Serve CNAMEs\n    else:\n        domain = Domain.objects.filter(domain=host).first()\n        if domain:\n            project_slug = domain.project.slug\n            request.cname = True\n            log.debug('Proxito CNAME: host=%s', host)\n        else:\n            # Some person is CNAMEing to us without configuring a domain - 404.\n            log.debug('CNAME 404: host=%s', host)\n            return render(\n                request, 'core/dns-404.html', context={'host': host}, status=404\n            )\n\n    log.debug('Proxito Project: slug=%s', project_slug)\n    return project_slug\n\n\nclass ProxitoMiddleware(MiddlewareMixin):\n\n    \"\"\"The actual middleware we'll be using in prod.\"\"\"\n\n    def process_request(self, request):  # noqa\n        if any([not settings.USE_SUBDOMAIN, 'localhost' in request.get_host(),\n                'testserver' in request.get_host()]):\n            log.debug('Not processing Proxito middleware')\n            return None\n\n        ret = map_host_to_project_slug(request)\n\n        # Handle returning a response\n        if hasattr(ret, 'status_code'):\n            return ret\n\n        # Otherwise set the slug on the request\n        request.host_project_slug = request.slug = ret\n\n        return None\n", "path": "readthedocs/proxito/middleware.py"}], "after_files": [{"content": "\"\"\"\nMiddleware for Proxito.\n\nThis is used to take the request and map the host to the proper project slug.\n\nAdditional processing is done to get the project from the URL in the ``views.py`` as well.\n\"\"\"\nimport logging\n\nfrom django.conf import settings\nfrom django.shortcuts import render\nfrom django.utils.deprecation import MiddlewareMixin\n\nfrom readthedocs.projects.models import Domain, Project\n\nlog = logging.getLogger(__name__)  # noqa\n\n\ndef map_host_to_project_slug(request):\n    \"\"\"\n    Take the request and map the host to the proper project slug.\n\n    We check, in order:\n\n    * The ``HTTP_X_RTD_SLUG`` host header for explicit Project mapping\n        - This sets ``request.rtdheader`` True\n    * The ``PUBLIC_DOMAIN`` where we can use the subdomain as the project name\n        - This sets ``request.subdomain`` True\n    * The hostname without port information, which maps to ``Domain`` objects\n        - This sets ``request.cname`` True\n    \"\"\"\n\n    host = request.get_host().lower().split(':')[0]\n    public_domain = settings.PUBLIC_DOMAIN.lower().split(':')[0]\n    host_parts = host.split('.')\n    public_domain_parts = public_domain.split('.')\n\n    project_slug = None\n\n    # Explicit Project slug being passed in\n    if 'HTTP_X_RTD_SLUG' in request.META:\n        project_slug = request.META['HTTP_X_RTD_SLUG'].lower()\n        if Project.objects.filter(slug=project_slug).exists():\n            request.rtdheader = True\n            log.info('Setting project based on X_RTD_SLUG header: %s', project_slug)\n            return project_slug\n\n    if public_domain in host or host == 'proxito':\n        # Serve from the PUBLIC_DOMAIN, ensuring it looks like `foo.PUBLIC_DOMAIN`\n        if public_domain_parts == host_parts[1:]:\n            project_slug = host_parts[0]\n            request.subdomain = True\n            log.debug('Proxito Public Domain: host=%s', host)\n            return project_slug\n        # TODO: This can catch some possibly valid domains (docs.readthedocs.io.com) for example\n        # But these feel like they might be phishing, etc. so let's block them for now.\n        log.warning('Weird variation on our hostname: host=%s', host)\n        return render(\n            request, 'core/dns-404.html', context={'host': host}, status=400\n        )\n\n    # Serve CNAMEs\n    domain = Domain.objects.filter(domain=host).first()\n    if domain:\n        project_slug = domain.project.slug\n        request.cname = True\n        log.debug('Proxito CNAME: host=%s', host)\n        return project_slug\n\n    # Some person is CNAMEing to us without configuring a domain - 404.\n    log.debug('CNAME 404: host=%s', host)\n    return render(\n        request, 'core/dns-404.html', context={'host': host}, status=404\n    )\n\n\nclass ProxitoMiddleware(MiddlewareMixin):\n\n    \"\"\"The actual middleware we'll be using in prod.\"\"\"\n\n    def process_request(self, request):  # noqa\n        if any([not settings.USE_SUBDOMAIN, 'localhost' in request.get_host(),\n                'testserver' in request.get_host()]):\n            log.debug('Not processing Proxito middleware')\n            return None\n\n        ret = map_host_to_project_slug(request)\n\n        # Handle returning a response\n        if hasattr(ret, 'status_code'):\n            return ret\n\n        log.debug('Proxito Project: slug=%s', ret)\n\n        # Otherwise set the slug on the request\n        request.host_project_slug = request.slug = ret\n\n        return None\n", "path": "readthedocs/proxito/middleware.py"}]}