void HeadersTest::caseInsensitivity() { QFETCH(QByteArray, qbytearray1); QFETCH(QByteArray, qbytearray2); const IByteArray ibytearray1 = IByteArray{qbytearray1.constData()}; const IByteArray ibytearray2 = qbytearray2; Headers headers; headers.insert(ibytearray1, qbytearray2); headers.insert(ibytearray2, qbytearray2); QCOMPARE(headers.count(ibytearray1), 2); QCOMPARE(headers.count(ibytearray2), 2); QVERIFY(headers.values(ibytearray1)[0] == headers.values(ibytearray2)[1]); /* ====================================================================== */ headers.clear(); headers.insert(ibytearray1, qbytearray2); headers.replace(ibytearray1, qbytearray1); headers.insert(ibytearray2, qbytearray2); QCOMPARE(headers.count(ibytearray1), 2); QCOMPARE(headers.count(ibytearray2), 2); QVERIFY(headers.values(ibytearray1)[0] != headers.values(ibytearray2)[1]); }
Uploads MultiPartFormDataParserPrivate::execute(char *buffer, int bufferSize) { Uploads ret; QByteArray header; Headers headers; qint64 startOffset; int boundaryPos = 0; ParserState state = FindBoundary; while (!body->atEnd()) { qint64 len = body->read(buffer, bufferSize); int i = 0; while (i < len) { switch (state) { case FindBoundary: i += findBoundary(buffer + i, len - i, state, boundaryPos); break; case EndBoundaryCR: // TODO the "--" case if (buffer[i] != '\r') { // qCDebug(CUTELYST_MULTIPART) << "EndBoundaryCR return!"; return ret; } state = EndBoundaryLF; break; case EndBoundaryLF: if (buffer[i] != '\n') { // qCDebug(CUTELYST_MULTIPART) << "EndBoundaryLF return!"; return ret; } header.clear(); state = StartHeaders; break; case StartHeaders: // qCDebug(CUTELYST_MULTIPART) << "StartHeaders" << body->pos() - len + i; if (buffer[i] == '\r') { state = EndHeaders; } else if (buffer[i] == '-') { // qCDebug(CUTELYST_MULTIPART) << "StartHeaders return!"; return ret; } else { char *pch = strchr(buffer + i, '\r'); if (pch == NULL) { header.append(buffer + i, len - i); i = len; } else { header.append(buffer + i, pch - buffer - i); i = pch - buffer; state = FinishHeader; } } break; case FinishHeader: // qCDebug(CUTELYST_MULTIPART) << "FinishHeader" << header; if (buffer[i] == '\n') { int dotdot = header.indexOf(':'); headers.setHeader(QString::fromLatin1(header.left(dotdot)), QString::fromLatin1(header.mid(dotdot + 1).trimmed())); header.clear(); state = StartHeaders; } else { // qCDebug(CUTELYST_MULTIPART) << "FinishHeader return!"; return ret; } break; case EndHeaders: // qCDebug(CUTELYST_MULTIPART) << "EndHeaders"; if (buffer[i] == '\n') { state = StartData; } else { // qCDebug(CUTELYST_MULTIPART) << "EndHeaders return!"; return ret; } break; case StartData: // qCDebug(CUTELYST_MULTIPART) << "StartData" << body->pos() - len + i; startOffset = body->pos() - len + i; state = EndData; case EndData: i += findBoundary(buffer + i, len - i, state, boundaryPos); if (state == EndBoundaryCR) { // qCDebug(CUTELYST_MULTIPART) << "EndData" << body->pos() - len + i - boundaryLength - 1; UploadPrivate *priv = new UploadPrivate(body); priv->headers = headers; headers.clear(); priv->startOffset = startOffset; priv->endOffset = body->pos() - len + i - boundaryLength - 1; ret << new Upload(priv); } } ++i; } } return ret; }
void clear () { myHead.clear(); myBody.clear(); }