diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index 852953815bb4d4782a3e7a6bdbe6b11dd3178689..a46010902edb93aea4bf8f6f67eee347637e1afc 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -965,7 +965,7 @@ void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket)
     case ReadingStatusState:
         if (!pSocket->canReadLine())
             return;
-        m_statusLine = pSocket->readLine();
+        m_statusLine = pSocket->readLine().trimmed();
         if (Q_UNLIKELY(!parseStatusLine(m_statusLine, &m_httpMajorVersion, &m_httpMinorVersion, &m_httpStatusCode, &m_httpStatusMessage))) {
             errorDescription = QWebSocket::tr("Invalid statusline in response: %1.").arg(QString::fromLatin1(m_statusLine));
             break;