Starscream.HTTPUpgradeError
Model Name: 2 iPhone models, 1 iPad Software Version: iOS 18.5 App version: Latest as of 5/26/2025 (can't get into the app to check, re downloaded from App Store)
Home Assistant Core Version 2025.5.1
Describe the bug App is not using secure HTTP for the websocket upgrade when adding a new server. "We couldn't connect to Home Assistant" Starscream.HTTPUpgradeError
To Reproduce Add a new server using the HTTPS scheme
Expected behavior App connects using secure HTTP for all API calls, including the websocket upgrade
Additional context
I specify https://servername/ when adding the server but:
In nginx access log, I see 301 redirects to HTTPS on the /api/websocket endpoint
In the app I get a Starscream.HTTPUpgradeError
In the exported app logs I see
[Error] [main] [Environment.swift:75] init() > WebSocket: Error: Optional(Starscream.HTTPUpgradeError.notAnUpgrade(301, ["Server": "nginx/1.26.3 (Ubuntu)", "Content-Type": "text/html", "Date": "Mon, 26 May 2025 03:17:41 GMT", "Connection": "keep-alive", "Location": "https://dev-hass.makerland.xyz/api/websocket", "Content-Length": "178"]))
With TCPdump I see traffic going to port 80
04:05:09.417593 eth0 In IP 10.3.5.140.52083 > hass02.makerland.xyz.http: Flags [S], seq 600926463, win 65535, options [mss 1460,nop,wscale 6,nop,nop,TS val 4049053127 ecr 0,sackOK,eol], length 0
In the configuration.yaml, I've defined the URLs with HTTPS also. HTTP isn't mentioned anywhere but starscream is trying to connect via insecure websocket. Not sure if that makes it a bug better suited for the starscream repo. I can't tell if it's a bug in the implementation of the library or the lib itself. Swift is up there with the programming languages that confuse me the most.
I can connect just fine in Safari. Right now I have the webpage added to my homescreen.
Issue I have is similar. Using Traefik with proxied Cloudflare sub domain. Sometimes connects with Android companion app. Just attempted with IOS on iPad and app tries to connect but get this issue. Several other sub domains on same infrastructure with zero issues. Any leads on how to resolve would be appreciated.
ChatGPT reckons: Likely Cause
The Starscream client (used in the Home Assistant iOS app) initiates the WebSocket connection using ws:// instead of wss://, despite the URL being defined with https:// in the server setup. This results in a redirect to HTTPS, which Starscream does not treat as a valid upgrade, leading to a notAnUpgrade(301) error.
⸻
🛠️ Root Fix
The issue should be fixed on the client side (iOS app). It needs to: • Detect that the original scheme is https:// and initiate the websocket as wss://, not ws://. • Handle 301 redirects more gracefully, although it’s better to avoid redirects for WebSocket entirely (many WS libraries including Starscream don’t support it well).
I recently ran into this myself -- I'm going to assume you are also manually entering in the url as I did? The problem is that devs need to change the textfield's property to:
textField.autocapitalizationType = .none
Or otherwise change all of the user entered url data to lower case. Currently the default behavior is to capitalize the first letter which also triggers some auto capitalization issues -- after I changed everything to lower case, it worked as expected.
@zestysoft added https://github.com/home-assistant/iOS/pull/3751
I got the same error and fixed by enabling websockets support in Nginx Reverse Proxy.