summaryrefslogtreecommitdiff
path: root/examples/webengine/customdialogs/server.cpp
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2021-07-20 09:29:17 +0200
committerMichal Klocek <michal.klocek@qt.io>2021-08-06 09:08:45 +0200
commitb18e707c4824004487e968fc95e8943dc3527506 (patch)
tree4946625af70e581e425a345af1989669c333aea7 /examples/webengine/customdialogs/server.cpp
parent4ff41d948059ebd014c4bb3a094cf0e21dd74ada (diff)
downloadqtwebengine-b18e707c4824004487e968fc95e8943dc3527506.tar.gz
Fix custom dialog example
Fix issue where ERR_UNEXPECTED_PROXY_AUTH error page is shown on proxy dialog request. * use qt.io url as dummy, otherwise CONNECT and GET requests to localhost end in proxy unexpected error. * in case of invalid authentication reload url instead of showing error page. * adjust app default width and height so dialog box is visible. Pick-to: 6.2 Change-Id: I16a1dade73f7cb0f4f6da48b7d6902a2e7a57b5b Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'examples/webengine/customdialogs/server.cpp')
-rw-r--r--examples/webengine/customdialogs/server.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/examples/webengine/customdialogs/server.cpp b/examples/webengine/customdialogs/server.cpp
index 39520e3b6..9b05d3a17 100644
--- a/examples/webengine/customdialogs/server.cpp
+++ b/examples/webengine/customdialogs/server.cpp
@@ -75,11 +75,20 @@ void Server::handleReadReady()
{
QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
Q_ASSERT(socket);
- QByteArray msg = socket->readAll();
- if (msg.contains(QByteArrayLiteral("OPEN_AUTH")))
+ m_data.append(socket->readAll());
+
+ // simply wait for whole request
+ if (!m_data.endsWith("\r\n\r\n"))
+ return;
+ if (m_data.contains(QByteArrayLiteral("OPEN_AUTH"))) {
socket->write("HTTP/1.1 401 Unauthorized\nWWW-Authenticate: "
"Basic realm=\"Very Restricted Area\"\r\n\r\n");
- if (msg.contains(QByteArrayLiteral("OPEN_PROXY")))
- socket->write("HTTP/1.1 407 Proxy Auth Required\nProxy-Authenticate: "
- "Basic realm=\"Proxy requires authentication\"\r\n\r\n");
+ m_data.clear();
+ return;
+ }
+
+ socket->write("HTTP/1.1 407 Proxy Auth Required\nProxy-Authenticate: "
+ "Basic realm=\"Proxy requires authentication\"\r\n"
+ "content-length: 0\r\n\r\n");
+ m_data.clear();
}