diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-02 10:28:20 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-17 05:25:53 +0000 |
commit | e90ed198b7c49cae8b0e067b343a6c4223f5464e (patch) | |
tree | 16314eff6725e1fdca8e90785b2ece5688c96933 /src/core/net/url_request_custom_job_proxy.cpp | |
parent | eb4ed30239b556694a70dc607d23cd9c6504d602 (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>
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); |