From cad7100fda1b27ba56c4d9efc6bceba62859dfbc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 13 May 2018 21:53:07 -0700 Subject: QByteArray: add compare() with case sensitivity options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Need to do the same for startsWith() and endsWith(). indexOf() is a lot harder. [ChangeLog][QtCore][QByteArray] Added compare(), which takes Qt::CaseSensitivity as one of the parameters. This function is more efficient than using toLower() or toUpper() and then comparing. Change-Id: Ib48364abee9f464c96c6fffd152e69bde4194df7 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Timur Pocheptsov --- src/network/access/qhttp2protocolhandler.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/network/access/qhttp2protocolhandler.cpp') diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index c207d6e240..df7f87efd4 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -97,16 +97,18 @@ HPack::HttpHeader build_headers(const QHttpNetworkRequest &request, quint32 maxH if (size.second > maxHeaderListSize) break; - QByteArray key(field.first.toLower()); - if (key == "connection" || key == "host" || key == "keep-alive" - || key == "proxy-connection" || key == "transfer-encoding") + if (field.first.compare("connection", Qt::CaseInsensitive) == 0 || + field.first.compare("host", Qt::CaseInsensitive) == 0 || + field.first.compare("keep-alive", Qt::CaseInsensitive) == 0 || + field.first.compare("proxy-connection", Qt::CaseInsensitive) == 0 || + field.first.compare("transfer-encoding", Qt::CaseInsensitive) == 0) continue; // Those headers are not valid (section 3.2.1) - from QSpdyProtocolHandler // TODO: verify with specs, which fields are valid to send .... // toLower - 8.1.2 .... "header field names MUST be converted to lowercase prior // to their encoding in HTTP/2. // A request or response containing uppercase header field names // MUST be treated as malformed (Section 8.1.2.6)". - header.push_back(HeaderField(key, field.second)); + header.push_back(HeaderField(field.first.toLower(), field.second)); } return header; @@ -1404,8 +1406,9 @@ bool QHttp2ProtocolHandler::tryReserveStream(const Http2::Frame &pushPromiseFram return false; } - const auto method = pseudoHeaders[":method"].toLower(); - if (method != "get" && method != "head") + const QByteArray method = pseudoHeaders[":method"]; + if (method.compare("get", Qt::CaseInsensitive) != 0 && + method.compare("head", Qt::CaseInsensitive) != 0) return false; QUrl url; -- cgit v1.2.3