summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-02-02 10:28:20 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-17 05:25:53 +0000
commite90ed198b7c49cae8b0e067b343a6c4223f5464e (patch)
tree16314eff6725e1fdca8e90785b2ece5688c96933
parenteb4ed30239b556694a70dc607d23cd9c6504d602 (diff)
Add charset parsing to custom scheme handler's content type
This was already assumed by test in tst_qwebengineprofile. [ChangeLog][QWebEngineUrlRequestJob] Charset is now explicitly parsed from provided contentType Change-Id: I9bfb1f94cf523fbe0f9796654b4114e61e904c92 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io> (cherry picked from commit c3ae834aaad8bc78d4e534d1b1346fcdba475a03) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/core/api/qwebengineurlrequestjob.cpp5
-rw-r--r--src/core/net/url_request_custom_job_proxy.cpp25
2 files changed, 17 insertions, 13 deletions
diff --git a/src/core/api/qwebengineurlrequestjob.cpp b/src/core/api/qwebengineurlrequestjob.cpp
index 3bb9d1732..13c0310c7 100644
--- a/src/core/api/qwebengineurlrequestjob.cpp
+++ b/src/core/api/qwebengineurlrequestjob.cpp
@@ -148,7 +148,10 @@ QMap<QByteArray, QByteArray> QWebEngineUrlRequestJob::requestHeaders() const
}
/*!
- Replies to the request with \a device and the MIME type \a contentType.
+ Replies to the request with \a device and the content type \a contentType.
+ Content type is similar to the HTTP Content-Type header, and can either be
+ a MIME type, or a MIME type and charset encoding combined like this:
+ "text/html; charset=utf-8".
The user has to be aware that \a device will be used on another thread
until the job is deleted. In case simultaneous access from the main thread
diff --git a/src/core/net/url_request_custom_job_proxy.cpp b/src/core/net/url_request_custom_job_proxy.cpp
index 758688709..65d652a1c 100644
--- a/src/core/net/url_request_custom_job_proxy.cpp
+++ b/src/core/net/url_request_custom_job_proxy.cpp
@@ -76,22 +76,23 @@ void URLRequestCustomJobProxy::release()
}
}
-// Fix me: this is never used
-/*
-void URLRequestCustomJobProxy::setReplyCharset(const std::string &charset)
-{
- DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- if (!m_job)
- return;
- m_job->m_charset = charset;
-}
-*/
-void URLRequestCustomJobProxy::reply(std::string mimeType, QIODevice *device)
+void URLRequestCustomJobProxy::reply(std::string contentType, QIODevice *device)
{
if (!m_client)
return;
DCHECK (!m_ioTaskRunner || m_ioTaskRunner->RunsTasksInCurrentSequence());
- m_client->m_mimeType = mimeType;
+ QByteArray qcontentType = QByteArray::fromStdString(contentType).toLower();
+ const int sidx = qcontentType.indexOf(';');
+ if (sidx > 0) {
+ const int cidx = qcontentType.indexOf("charset=", sidx);
+ if (cidx > 0) {
+ m_client->m_charset = qcontentType.mid(cidx + 8).toStdString();
+ qcontentType = qcontentType.first(sidx);
+ } else {
+ qWarning() << "QWebEngineUrlRequestJob::reply(): Unrecognized content-type format with ';'" << qcontentType;
+ }
+ }
+ m_client->m_mimeType = qcontentType.toStdString();
m_client->m_device = device;
if (m_client->m_device && !m_client->m_device->isReadable())
m_client->m_device->open(QIODevice::ReadOnly);