diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-02-19 14:03:45 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-02-20 08:09:53 +0000 |
commit | 85a8ea105646c7d871f982b890ef5f6faa91824d (patch) | |
tree | 876e6bc7e22fcf0984ee806c68a423eeaebde58f /src | |
parent | 0a42c6aff61142f97b6288b4504357a26ef43855 (diff) | |
download | qtwebsockets-85a8ea105646c7d871f982b890ef5f6faa91824d.tar.gz |
fix the port in Host field in handshake request
Task-number: QTBUG-39355
Change-Id: I06993193fe9618ace93552aed573a3eee5de18fa
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/websockets/qwebsockethandshakerequest.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/websockets/qwebsockethandshakerequest.cpp b/src/websockets/qwebsockethandshakerequest.cpp index 94d99cd..6c8c9cf 100644 --- a/src/websockets/qwebsockethandshakerequest.cpp +++ b/src/websockets/qwebsockethandshakerequest.cpp @@ -222,10 +222,22 @@ void QWebSocketHandshakeRequest::readHandshake(QTextStream &textStream) headerLine = textStream.readLine(); } - const QString host = m_headers.value(QStringLiteral("host"), QString()); m_requestUrl = QUrl::fromEncoded(resourceName.toLatin1()); - if (m_requestUrl.isRelative()) + QString host = m_headers.value(QStringLiteral("host"), QString()); + if (m_requestUrl.isRelative()) { + // see http://tools.ietf.org/html/rfc6455#page-17 + // No. 4 item in "The requirements for this handshake" + int idx = host.indexOf(":"); + bool ok = false; + int port; + if (idx != -1) { + port = host.rightRef(host.length() - idx - 1).toInt(&ok); + host.truncate(idx); + } m_requestUrl.setHost(host); + if (ok) + m_requestUrl.setPort(port); + } if (m_requestUrl.scheme().isEmpty()) { const QString scheme = isSecure() ? QStringLiteral("wss") : QStringLiteral("ws"); m_requestUrl.setScheme(scheme); |