Skip to content

Commit

Permalink
Merge pull request #90698 from Faless/fix/web/serve_py_dual_stack_win…
Browse files Browse the repository at this point in the history
…dows

[Web] Fix serve.py utility on Windows
  • Loading branch information
akien-mga committed Apr 16, 2024
2 parents 8901e87 + 67a51c9 commit 79173d1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion platform/web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
import os
import sys
import argparse
import contextlib
import socket
import subprocess


# See cpython GH-17851 and GH-17864.
class DualStackServer(HTTPServer):
def server_bind(self):
# Suppress exception when protocol is IPv4.
with contextlib.suppress(Exception):
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
return super().server_bind()


class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
Expand All @@ -32,7 +43,7 @@ def serve(root, port, run_browser):
print("Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this).")
shell_open(f"http://127.0.0.1:{port}")

test(CORSRequestHandler, HTTPServer, port=port)
test(CORSRequestHandler, DualStackServer, port=port)


if __name__ == "__main__":
Expand Down

0 comments on commit 79173d1

Please sign in to comment.