diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-02 10:28:20 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-16 23:14:37 +0100 |
commit | c3ae834aaad8bc78d4e534d1b1346fcdba475a03 (patch) | |
tree | b7350548e7117c11e2ce3c3bc13dce233b2e1d9e /src/core/net/url_request_custom_job_proxy.cpp | |
parent | 9f4e2a220c14c35a3634f044e386f95326bc3a05 (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
Pick-to: 6.3
Change-Id: I9bfb1f94cf523fbe0f9796654b4114e61e904c92
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core/net/url_request_custom_job_proxy.cpp')
-rw-r--r-- | src/core/net/url_request_custom_job_proxy.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
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); |