Fix HTTP proxy URL parsing for wss:// WebSocket URLs (#3168)
authorChris <chris@sicmedia.net>
Sun, 15 Feb 2026 17:32:54 +0000 (11:32 -0600)
committerGitHub <noreply@github.com>
Sun, 15 Feb 2026 17:32:54 +0000 (12:32 -0500)
* Fix HTTP proxy URL parsing for wss:// WebSocket URLs

The HTTP proxy handler constructed the local HTTP URL by stripping
"ws://" from local_ws_url with a simple string replace. When the
server uses SSL, local_ws_url is "wss://..." which didn't match the
replace, producing a broken URL like "http://wss:/imageproxy?..." and
causing all proxy requests to fail with DNS resolution errors.

Use urllib.parse.urlparse instead, which correctly handles both ws://
and wss:// schemes.

* Move urlparse import to top-level to fix PLC0415 lint error

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
music_assistant/controllers/webserver/remote_access/gateway.py

index 68bed470feb2229bb38158a18a4e229bf0cbf70c..042ff8b3f6b0a24ae0c3c15295b0f7bbc2f34775 100644 (file)
@@ -14,6 +14,7 @@ import logging
 from collections.abc import Awaitable, Callable
 from dataclasses import dataclass, field
 from typing import TYPE_CHECKING, Any
+from urllib.parse import urlparse
 
 import aiohttp
 from aiortc import RTCConfiguration, RTCIceServer, RTCPeerConnection, RTCSessionDescription
@@ -627,11 +628,11 @@ class WebRTCGateway:
         path = request_data.get("path", "/")
         headers = request_data.get("headers", {})
 
-        # Build local HTTP URL
-        # Extract host and port from local_ws_url (ws://localhost:8095/ws)
-        ws_url_parts = self.local_ws_url.replace("ws://", "").split("/")
-        host_port = ws_url_parts[0]  # localhost:8095
-        local_http_url = f"http://{host_port}{path}"
+        # Build local HTTP URL from the WebSocket URL.
+        # Handle both ws:// and wss:// schemes.
+        parsed = urlparse(self.local_ws_url)
+        http_scheme = "https" if parsed.scheme == "wss" else "http"
+        local_http_url = f"{http_scheme}://{parsed.netloc}{path}"
 
         self.logger.debug("HTTP proxy request: %s %s", method, local_http_url)