shelf
shelf copied to clipboard
WebSocketException: Connection to '${url}' was not upgraded to websocket
I know from https://github.com/dart-lang/web_socket_channel/issues/164#issuecomment-1026354706 dart will convert all request header key to lowercase. and in this repo,we can see some code like this:
final connection = request.headers['Connection'];
if (connection == null) return _notFound();
final tokens =
connection.toLowerCase().split(',').map((token) => token.trim());
if (!tokens.contains('upgrade')) return _notFound();
final upgrade = request.headers['Upgrade'];
if (upgrade == null) return _notFound();
if (upgrade.toLowerCase() != 'websocket') return _notFound();
and my flutter app for mac desktop in debug mode cannot connect this websocket powered by webSocketHandler,then i change webSocketHandler key to lowercase,like this:
final connection = request.headers['Connection'];
if (connection == null) return _notFound();
final tokens =
connection.toLowerCase().split(',').map((token) => token.trim());
if (!tokens.contains('upgrade')) return _notFound();
final upgrade = request.headers['upgrade'];
if (upgrade == null) return _notFound();
if (upgrade.toLowerCase() != 'websocket') return _notFound();
everything is working properly. oddly enough, it all worked in Android,web, and release mode on mac without any changes
Had some strange behavior with this as well, we have many websockets in our application that have been functioning well for over a year or two now, had a more complex socket case that should have functioned no problem(worked well in debug && in release mode, but failed in our actual production application).
I come to find out that something with the --obfuscate flag that messed with the request up giving back the same clientside error