You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
[Web] Fix serve.py utility on Windows
IPv6 dual stack is disabled by default, and Windows resolves wildcard addresses to an IPv6 by default, so connecting through the local IPv4 address would not work. This enables IPv6 dual stacking for the HTTP server by default like done in upstream python when launching the module from CLI.
This commit is contained in:
@@ -5,9 +5,20 @@ from pathlib import Path
|
||||
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")
|
||||
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user