summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/websockets/qwebsocket_wasm_p.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/websockets/qwebsocket_wasm_p.cpp b/src/websockets/qwebsocket_wasm_p.cpp
index d38c527..9e73e1d 100644
--- a/src/websockets/qwebsocket_wasm_p.cpp
+++ b/src/websockets/qwebsocket_wasm_p.cpp
@@ -12,6 +12,8 @@
#include <emscripten/websocket.h>
#include <emscripten/val.h>
+#include <QHostAddress>
+
static EM_BOOL q_onWebSocketErrorCallback(int eventType,
const EmscriptenWebSocketErrorEvent *e,
void *userData)
@@ -150,12 +152,22 @@ void QWebSocketPrivate::open(const QNetworkRequest &request,
return;
}
- if (isSecureContext && url.scheme() == QStringLiteral("ws")) {
- const QString message =
+ // exception for localhost/127.0.0.1/[::1]
+ // localhost has special privledges
+
+ QHostAddress hostAddress(url.host());
+
+ bool hostAddressIsLocal = (hostAddress == QHostAddress::LocalHost
+ || hostAddress == QHostAddress::LocalHostIPv6);
+
+ if (url.host() != QStringLiteral("localhost") && !hostAddressIsLocal) {
+ if (isSecureContext && url.scheme() == QStringLiteral("ws")) {
+ const QString message =
QWebSocket::tr("Unsupported WebSocket scheme: %1").arg(url.scheme());
- setErrorString(message);
- emitErrorOccurred(QAbstractSocket::UnsupportedSocketOperationError);
- return;
+ setErrorString(message);
+ emitErrorOccurred(QAbstractSocket::UnsupportedSocketOperationError);
+ return;
+ }
}
EmscriptenWebSocketCreateAttributes attr;