Skip to content

Commit 852efca

Browse files
author
Kaloyan Chehlarski
committed
Remove custom Content-Type parsing code from URLRequestCustomJobProxy
We don't need to be parsing Content-Type headers ourselves, and the existing code won't parse the charset correctly in all cases. Instead, the parsing is now done through net::HttpUtil::ParseContentType(). Pick-to: 6.9 6.8 Change-Id: I94054a8fc1aa3a2b9f8c504e194530719ccdcc11 Reviewed-by: Anu Aliyas <[email protected]>
1 parent ccb741f commit 852efca

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/core/net/url_request_custom_job_proxy.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "content/public/browser/browser_thread.h"
88
#include "net/base/net_errors.h"
9+
#include "net/http/http_util.h"
910
#include "services/network/public/cpp/resource_request_body.h"
1011

1112
#include "api/qwebengineurlrequestjob.h"
@@ -47,20 +48,8 @@ void URLRequestCustomJobProxy::reply(std::string contentType, QIODevice *device,
4748
if (!m_client)
4849
return;
4950
DCHECK (!m_ioTaskRunner || m_ioTaskRunner->RunsTasksInCurrentSequence());
50-
QByteArray qcontentType = QByteArray::fromStdString(contentType).toLower();
51-
const int sidx = qcontentType.indexOf(';');
52-
if (sidx > 0) {
53-
const int cidx = qcontentType.indexOf("charset=", sidx);
54-
if (cidx > 0) {
55-
m_client->m_charset = qcontentType.mid(cidx + 8).trimmed().toStdString();
56-
qcontentType = qcontentType.first(sidx);
57-
} else {
58-
qWarning("QWebEngineUrlRequestJob::reply(): Unrecognized content-type format with ';' "
59-
"%s",
60-
qcontentType.constData());
61-
}
62-
}
63-
m_client->m_mimeType = qcontentType.trimmed().toStdString();
51+
bool hadCharset = false;
52+
net::HttpUtil::ParseContentType(contentType, &m_client->m_mimeType, &m_client->m_charset, &hadCharset, nullptr);
6453
m_client->m_device = device;
6554
m_client->m_additionalResponseHeaders = std::move(additionalResponseHeaders);
6655
if (m_client->m_device && !m_client->m_device->isReadable())

0 commit comments

Comments
 (0)