qtwasmserver to serve assets from the provided path parameter

qtwasmserver accepts a positional path argument which tells where to
serve the assets from. The argument wasn't actually used, and this
resulted in always using the cwd.

In addition add a check for the path directory existence. Otherwise
this becomes only visible as a 404 Not Found error.

Amends: 156e5c8b690d01ad3043d2163168c4ea3608a046

Fixes: QTBUG-134393
Change-Id: Iacfafe8a2fb2409169b09a17dbc9ffed0ad16fdf
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
(cherry picked from commit fcada7c5c395a7006ecef184c3ca43fff1023616)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Juha Vuolle 2025-03-05 09:02:20 +02:00 committed by Qt Cherry-pick Bot
parent aca60117ee
commit 7ad9a2d391

View File

@ -15,6 +15,7 @@ from enum import Enum
from http import HTTPStatus
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from subprocess import run
from functools import partial
import brotli
import netifaces as ni
@ -155,7 +156,7 @@ def select_http_handler_class(compression_mode, address):
return CompressionHttpRequesthandler
# Serve cwd from http(s)://address:port, with certificates from certdir if set
# Serve serve_path from http(s)://address:port, with certificates from certdir if set
def serve_on_thread(
address,
port,
@ -164,12 +165,13 @@ def serve_on_thread(
cert_key_file,
compression_mode,
cross_origin_isolation,
serve_path,
):
handler = select_http_handler_class(compression_mode, address)
handler.cross_origin_isolation = cross_origin_isolation
try:
httpd = ThreadingHTTPServer((address, port), handler)
httpd = ThreadingHTTPServer((address, port), partial(handler, directory=serve_path))
except Exception as e:
print(f"\n### Error starting HTTP server: {e}\n")
exit(1)
@ -243,6 +245,10 @@ def main():
serve_path = args.path
cross_origin_isolation = args.cross_origin_isolation
if not os.path.isdir(serve_path):
print(f"The provided path '{serve_path}' does not exist or is not a directory")
exit(1)
compression_mode = CompressionMode.AUTO
if args.compress_always:
compression_mode = CompressionMode.ALWAYS
@ -285,6 +291,7 @@ def main():
cert_key_file,
compression_mode,
cross_origin_isolation,
serve_path,
)
if has_certificate:
@ -298,6 +305,7 @@ def main():
cert_key_file,
compression_mode,
cross_origin_isolation,
serve_path,
)