summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2021-07-20 09:29:17 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-10 13:56:48 +0000
commit0746e419c1ad5648028d58edd4a2c68fcf586f79 (patch)
treec184df1f6a55e2da07007f7aa00579959a879080
parent6d2253539b8bb19280265264aeb4ffc96d9fb15b (diff)
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. Change-Id: I16a1dade73f7cb0f4f6da48b7d6902a2e7a57b5b Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io> (cherry picked from commit b18e707c4824004487e968fc95e8943dc3527506) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/webengine/customdialogs/WebView.qml8
-rw-r--r--examples/webengine/customdialogs/index.html2
-rw-r--r--examples/webengine/customdialogs/main.qml6
-rw-r--r--examples/webengine/customdialogs/server.cpp19
-rw-r--r--examples/webengine/customdialogs/server.h1
5 files changed, 25 insertions, 11 deletions
diff --git a/examples/webengine/customdialogs/WebView.qml b/examples/webengine/customdialogs/WebView.qml
index 5d388e467..61bbea87e 100644
--- a/examples/webengine/customdialogs/WebView.qml
+++ b/examples/webengine/customdialogs/WebView.qml
@@ -52,7 +52,7 @@ import QtQuick
import QtWebEngine
WebEngineView {
-
+ id: view
url: "qrc:/index.html"
property bool useDefaultDialogs: true
signal openForm(var form)
@@ -115,9 +115,11 @@ WebEngineView {
}
onAuthenticationDialogRequested: function(request) {
- if (useDefaultDialogs)
+ if (useDefaultDialogs) {
+ // do not show proxy error page
+ view.url = "qrc:/index.html"
return;
-
+ }
request.accepted = true;
openForm({item: Qt.resolvedUrl("forms/Authentication.qml"),
properties: {"request": request}});
diff --git a/examples/webengine/customdialogs/index.html b/examples/webengine/customdialogs/index.html
index 69c0e6b21..e9fb56228 100644
--- a/examples/webengine/customdialogs/index.html
+++ b/examples/webengine/customdialogs/index.html
@@ -18,7 +18,7 @@
Open Authentication Dialog</button></td>
</tr>
<tr>
- <td><button class="button" onclick="window.location = 'http://localhost.:5555/OPEN_PROXY'">
+ <td><button class="button" onclick="window.location = 'http://www.qt.io'">
Open Proxy Dialog</button></td>
</tr>
<tr>
diff --git a/examples/webengine/customdialogs/main.qml b/examples/webengine/customdialogs/main.qml
index a5ff925b4..529737e99 100644
--- a/examples/webengine/customdialogs/main.qml
+++ b/examples/webengine/customdialogs/main.qml
@@ -55,8 +55,8 @@ import QtQuick.Window
Window {
id: mainWindow
- width: 350
- height: 550
+ width: 800
+ height: 600
visible: true
StackView {
@@ -85,6 +85,8 @@ Window {
function closeForm()
{
pop(main);
+ // reset url in case of proxy error
+ webView.url = "qrc:/index.html"
}
function openForm(form)
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();
}
diff --git a/examples/webengine/customdialogs/server.h b/examples/webengine/customdialogs/server.h
index 501aef533..0a495cc4b 100644
--- a/examples/webengine/customdialogs/server.h
+++ b/examples/webengine/customdialogs/server.h
@@ -70,6 +70,7 @@ private slots:
private:
QTcpServer m_server;
+ QByteArray m_data;
};
#endif // SERVER_H