We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove X-Forwarded-Proto/X-Forwarded-Port h2o workaround
[In `warehouse/utils/wsgi.py`](https://github.com/pypa/warehouse/blob/master/warehouse/utils/wsgi.py#L51-L58) we note that once https://github.com/h2o/h2o/issues/883 is solved, we can remove a few lines about `X-Forwarded-Port` and `X-Forwarded-Proto`. They resolved that issue in May 2016 and [have released several new versions since then](https://h2o.examp1e.net/). OK to remove workaround?

Followup to b8b9f385382cd659750c694cf8b1b3db6f1f6d35 .

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `warehouse/utils/wsgi.py`
Content:
```
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12 
13 import hmac
14 
15 
16 def _forwarded_value(values, num_proxies):
17     values = [v.strip() for v in values.split(",")]
18     if len(values) >= num_proxies:
19         return values[-num_proxies]
20 
21 
22 class ProxyFixer:
23 
24     def __init__(self, app, token, num_proxies=1):
25         self.app = app
26         self.token = token
27         self.num_proxies = num_proxies
28 
29     def __call__(self, environ, start_response):
30         # Determine if the request comes from a trusted proxy or not by looking
31         # for a token in the request.
32         request_token = environ.get("HTTP_WAREHOUSE_TOKEN")
33         if (request_token is not None and
34                 hmac.compare_digest(self.token, request_token)):
35             # Compute our values from the environment.
36             proto = environ.get("HTTP_WAREHOUSE_PROTO", "")
37             remote_addr = environ.get("HTTP_WAREHOUSE_IP", "")
38             host = environ.get("HTTP_WAREHOUSE_HOST", "")
39         # If we're not getting headers from a trusted third party via the
40         # specialized Warehouse-* headers, then we'll fall back to looking at
41         # X-Fowarded-* headers, assuming that whatever we have in front of us
42         # will strip invalid ones.
43         else:
44             proto = environ.get("HTTP_X_FORWARDED_PROTO", "")
45             remote_addr = _forwarded_value(
46                 environ.get("HTTP_X_FORWARDED_FOR", ""),
47                 self.num_proxies,
48             )
49             host = environ.get("HTTP_X_FORWARDED_HOST", "")
50 
51             # If we have a X-Forwarded-Port and it disagreed with
52             # X-Forwarded-Proto then we're going to listen to X-Forwarded-Port
53             # instead. This is because h2o overwrites X-Forwarded-Proto but not
54             # X-Forwarded-Port
55             # TODO: Note, this can go away if/once h2o/h2o#883 is solved.
56             port = environ.get("HTTP_X_FORWARDED_PORT", "")
57             if port == "443":
58                 proto = "https"
59 
60         # Put the new header values into our environment.
61         if remote_addr:
62             environ["REMOTE_ADDR"] = remote_addr
63         if host:
64             environ["HTTP_HOST"] = host
65         if proto:
66             environ["wsgi.url_scheme"] = proto
67 
68         # Remove any of the forwarded or warehouse headers from the environment
69         for header in {
70                 "HTTP_X_FORWARDED_PROTO", "HTTP_X_FORWARDED_FOR",
71                 "HTTP_X_FORWARDED_HOST", "HTTP_X_FORWARDED_PORT",
72                 "HTTP_WAREHOUSE_TOKEN", "HTTP_WAREHOUSE_PROTO",
73                 "HTTP_WAREHOUSE_IP", "HTTP_WAREHOUSE_HOST"}:
74             if header in environ:
75                 del environ[header]
76 
77         # Dispatch to the real underlying application.
78         return self.app(environ, start_response)
79 
80 
81 class VhmRootRemover:
82 
83     def __init__(self, app):
84         self.app = app
85 
86     def __call__(self, environ, start_response):
87         # Delete the X-Vhm-Root header if it exists.
88         if "HTTP_X_VHM_ROOT" in environ:
89             del environ["HTTP_X_VHM_ROOT"]
90 
91         return self.app(environ, start_response)
92 
93 
94 class HostRewrite:
95 
96     # TODO: This entire class should not be required.
97 
98     def __init__(self, app):
99         self.app = app
100 
101     def __call__(self, environ, start_response):
102         # If the host header matches upload.pypi.io, then we want to rewrite it
103         # so that it is instead upload.pypi.org.
104         if environ.get("HTTP_HOST", "").lower() == "upload.pypi.io":
105             environ["HTTP_HOST"] = "upload.pypi.org"
106 
107         return self.app(environ, start_response)
108
```
--- 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()

```

diff --git a/warehouse/utils/wsgi.py b/warehouse/utils/wsgi.py
--- a/warehouse/utils/wsgi.py
+++ b/warehouse/utils/wsgi.py
@@ -48,15 +48,6 @@
             )
             host = environ.get("HTTP_X_FORWARDED_HOST", "")
 
-            # If we have a X-Forwarded-Port and it disagreed with
-            # X-Forwarded-Proto then we're going to listen to X-Forwarded-Port
-            # instead. This is because h2o overwrites X-Forwarded-Proto but not
-            # X-Forwarded-Port
-            # TODO: Note, this can go away if/once h2o/h2o#883 is solved.
-            port = environ.get("HTTP_X_FORWARDED_PORT", "")
-            if port == "443":
-                proto = "https"
-
         # Put the new header values into our environment.
         if remote_addr:
             environ["REMOTE_ADDR"] = remote_addr

{"golden_diff": "diff --git a/warehouse/utils/wsgi.py b/warehouse/utils/wsgi.py\n--- a/warehouse/utils/wsgi.py\n+++ b/warehouse/utils/wsgi.py\n@@ -48,15 +48,6 @@\n             )\n             host = environ.get(\"HTTP_X_FORWARDED_HOST\", \"\")\n \n-            # If we have a X-Forwarded-Port and it disagreed with\n-            # X-Forwarded-Proto then we're going to listen to X-Forwarded-Port\n-            # instead. This is because h2o overwrites X-Forwarded-Proto but not\n-            # X-Forwarded-Port\n-            # TODO: Note, this can go away if/once h2o/h2o#883 is solved.\n-            port = environ.get(\"HTTP_X_FORWARDED_PORT\", \"\")\n-            if port == \"443\":\n-                proto = \"https\"\n-\n         # Put the new header values into our environment.\n         if remote_addr:\n             environ[\"REMOTE_ADDR\"] = remote_addr\n", "issue": "Remove X-Forwarded-Proto/X-Forwarded-Port h2o workaround\n[In `warehouse/utils/wsgi.py`](https://github.com/pypa/warehouse/blob/master/warehouse/utils/wsgi.py#L51-L58) we note that once https://github.com/h2o/h2o/issues/883 is solved, we can remove a few lines about `X-Forwarded-Port` and `X-Forwarded-Proto`. They resolved that issue in May 2016 and [have released several new versions since then](https://h2o.examp1e.net/). OK to remove workaround?\r\n\r\nFollowup to b8b9f385382cd659750c694cf8b1b3db6f1f6d35 .\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport hmac\n\n\ndef _forwarded_value(values, num_proxies):\n    values = [v.strip() for v in values.split(\",\")]\n    if len(values) >= num_proxies:\n        return values[-num_proxies]\n\n\nclass ProxyFixer:\n\n    def __init__(self, app, token, num_proxies=1):\n        self.app = app\n        self.token = token\n        self.num_proxies = num_proxies\n\n    def __call__(self, environ, start_response):\n        # Determine if the request comes from a trusted proxy or not by looking\n        # for a token in the request.\n        request_token = environ.get(\"HTTP_WAREHOUSE_TOKEN\")\n        if (request_token is not None and\n                hmac.compare_digest(self.token, request_token)):\n            # Compute our values from the environment.\n            proto = environ.get(\"HTTP_WAREHOUSE_PROTO\", \"\")\n            remote_addr = environ.get(\"HTTP_WAREHOUSE_IP\", \"\")\n            host = environ.get(\"HTTP_WAREHOUSE_HOST\", \"\")\n        # If we're not getting headers from a trusted third party via the\n        # specialized Warehouse-* headers, then we'll fall back to looking at\n        # X-Fowarded-* headers, assuming that whatever we have in front of us\n        # will strip invalid ones.\n        else:\n            proto = environ.get(\"HTTP_X_FORWARDED_PROTO\", \"\")\n            remote_addr = _forwarded_value(\n                environ.get(\"HTTP_X_FORWARDED_FOR\", \"\"),\n                self.num_proxies,\n            )\n            host = environ.get(\"HTTP_X_FORWARDED_HOST\", \"\")\n\n            # If we have a X-Forwarded-Port and it disagreed with\n            # X-Forwarded-Proto then we're going to listen to X-Forwarded-Port\n            # instead. This is because h2o overwrites X-Forwarded-Proto but not\n            # X-Forwarded-Port\n            # TODO: Note, this can go away if/once h2o/h2o#883 is solved.\n            port = environ.get(\"HTTP_X_FORWARDED_PORT\", \"\")\n            if port == \"443\":\n                proto = \"https\"\n\n        # Put the new header values into our environment.\n        if remote_addr:\n            environ[\"REMOTE_ADDR\"] = remote_addr\n        if host:\n            environ[\"HTTP_HOST\"] = host\n        if proto:\n            environ[\"wsgi.url_scheme\"] = proto\n\n        # Remove any of the forwarded or warehouse headers from the environment\n        for header in {\n                \"HTTP_X_FORWARDED_PROTO\", \"HTTP_X_FORWARDED_FOR\",\n                \"HTTP_X_FORWARDED_HOST\", \"HTTP_X_FORWARDED_PORT\",\n                \"HTTP_WAREHOUSE_TOKEN\", \"HTTP_WAREHOUSE_PROTO\",\n                \"HTTP_WAREHOUSE_IP\", \"HTTP_WAREHOUSE_HOST\"}:\n            if header in environ:\n                del environ[header]\n\n        # Dispatch to the real underlying application.\n        return self.app(environ, start_response)\n\n\nclass VhmRootRemover:\n\n    def __init__(self, app):\n        self.app = app\n\n    def __call__(self, environ, start_response):\n        # Delete the X-Vhm-Root header if it exists.\n        if \"HTTP_X_VHM_ROOT\" in environ:\n            del environ[\"HTTP_X_VHM_ROOT\"]\n\n        return self.app(environ, start_response)\n\n\nclass HostRewrite:\n\n    # TODO: This entire class should not be required.\n\n    def __init__(self, app):\n        self.app = app\n\n    def __call__(self, environ, start_response):\n        # If the host header matches upload.pypi.io, then we want to rewrite it\n        # so that it is instead upload.pypi.org.\n        if environ.get(\"HTTP_HOST\", \"\").lower() == \"upload.pypi.io\":\n            environ[\"HTTP_HOST\"] = \"upload.pypi.org\"\n\n        return self.app(environ, start_response)\n", "path": "warehouse/utils/wsgi.py"}], "after_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport hmac\n\n\ndef _forwarded_value(values, num_proxies):\n    values = [v.strip() for v in values.split(\",\")]\n    if len(values) >= num_proxies:\n        return values[-num_proxies]\n\n\nclass ProxyFixer:\n\n    def __init__(self, app, token, num_proxies=1):\n        self.app = app\n        self.token = token\n        self.num_proxies = num_proxies\n\n    def __call__(self, environ, start_response):\n        # Determine if the request comes from a trusted proxy or not by looking\n        # for a token in the request.\n        request_token = environ.get(\"HTTP_WAREHOUSE_TOKEN\")\n        if (request_token is not None and\n                hmac.compare_digest(self.token, request_token)):\n            # Compute our values from the environment.\n            proto = environ.get(\"HTTP_WAREHOUSE_PROTO\", \"\")\n            remote_addr = environ.get(\"HTTP_WAREHOUSE_IP\", \"\")\n            host = environ.get(\"HTTP_WAREHOUSE_HOST\", \"\")\n        # If we're not getting headers from a trusted third party via the\n        # specialized Warehouse-* headers, then we'll fall back to looking at\n        # X-Fowarded-* headers, assuming that whatever we have in front of us\n        # will strip invalid ones.\n        else:\n            proto = environ.get(\"HTTP_X_FORWARDED_PROTO\", \"\")\n            remote_addr = _forwarded_value(\n                environ.get(\"HTTP_X_FORWARDED_FOR\", \"\"),\n                self.num_proxies,\n            )\n            host = environ.get(\"HTTP_X_FORWARDED_HOST\", \"\")\n\n        # Put the new header values into our environment.\n        if remote_addr:\n            environ[\"REMOTE_ADDR\"] = remote_addr\n        if host:\n            environ[\"HTTP_HOST\"] = host\n        if proto:\n            environ[\"wsgi.url_scheme\"] = proto\n\n        # Remove any of the forwarded or warehouse headers from the environment\n        for header in {\n                \"HTTP_X_FORWARDED_PROTO\", \"HTTP_X_FORWARDED_FOR\",\n                \"HTTP_X_FORWARDED_HOST\", \"HTTP_X_FORWARDED_PORT\",\n                \"HTTP_WAREHOUSE_TOKEN\", \"HTTP_WAREHOUSE_PROTO\",\n                \"HTTP_WAREHOUSE_IP\", \"HTTP_WAREHOUSE_HOST\"}:\n            if header in environ:\n                del environ[header]\n\n        # Dispatch to the real underlying application.\n        return self.app(environ, start_response)\n\n\nclass VhmRootRemover:\n\n    def __init__(self, app):\n        self.app = app\n\n    def __call__(self, environ, start_response):\n        # Delete the X-Vhm-Root header if it exists.\n        if \"HTTP_X_VHM_ROOT\" in environ:\n            del environ[\"HTTP_X_VHM_ROOT\"]\n\n        return self.app(environ, start_response)\n\n\nclass HostRewrite:\n\n    # TODO: This entire class should not be required.\n\n    def __init__(self, app):\n        self.app = app\n\n    def __call__(self, environ, start_response):\n        # If the host header matches upload.pypi.io, then we want to rewrite it\n        # so that it is instead upload.pypi.org.\n        if environ.get(\"HTTP_HOST\", \"\").lower() == \"upload.pypi.io\":\n            environ[\"HTTP_HOST\"] = \"upload.pypi.org\"\n\n        return self.app(environ, start_response)\n", "path": "warehouse/utils/wsgi.py"}]}