From 2464131f35f7f41cb0a814919d1d829f5c4edebb Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 15 Feb 2026 11:32:54 -0600 Subject: [PATCH] Fix HTTP proxy URL parsing for wss:// WebSocket URLs (#3168) * 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 --------- Co-authored-by: Claude Opus 4.6 --- .../controllers/webserver/remote_access/gateway.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/music_assistant/controllers/webserver/remote_access/gateway.py b/music_assistant/controllers/webserver/remote_access/gateway.py index 68bed470..042ff8b3 100644 --- a/music_assistant/controllers/webserver/remote_access/gateway.py +++ b/music_assistant/controllers/webserver/remote_access/gateway.py @@ -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) -- 2.34.1