35 if ( !mReply )
return;
43 QMap<QByteArray, QByteArray>
headers;
44 const auto constRawHeaderList = mReply->rawHeaderList();
45 for (
const QByteArray &h : constRawHeaderList )
47 headers.insert( h, mReply->rawHeader( h ) );
50 mBodies.append( mReply->readAll() );
54 const QString contentType = mReply->header( QNetworkRequest::ContentTypeHeader ).toString();
57 const thread_local QRegularExpression re(
".*boundary=\"?([^\"]+)\"?\\s?", QRegularExpression::CaseInsensitiveOption );
58 const QRegularExpressionMatch match = re.match( contentType );
59 if ( !( match.capturedStart( 0 ) == 0 ) )
61 mError = tr(
"Cannot find boundary in multipart content type" );
65 QString boundary = match.captured( 1 );
66 QgsDebugMsgLevel( QStringLiteral(
"boundary = %1 size = %2" ).arg( boundary ).arg( boundary.size() ), 2 );
67 boundary =
"--" + boundary;
70 const QByteArray data = mReply->readAll();
72 from = data.indexOf( boundary.toLatin1(), 0 ) + boundary.length() + 1;
78 to = data.indexOf( boundary.toLatin1(), from );
81 QgsDebugMsgLevel( QStringLiteral(
"No more boundaries, rest size = %1" ).arg( data.size() - from - 1 ), 2 );
83 if ( data.size() - from - 1 == 2 && QString( data.mid( from, 2 ) ) == QLatin1String(
"--" ) )
90 if ( data.size() - from > 1 )
99 QgsDebugMsgLevel( QStringLiteral(
"part %1 - %2" ).arg( from ).arg( to ), 2 );
100 QByteArray part = data.mid( from, to - from );
102 while ( !part.isEmpty() && ( part.at( 0 ) ==
'\r' || part.at( 0 ) ==
'\n' ) )
109 while ( pos < part.size() - 1 )
111 if ( part.at( pos ) ==
'\n' && ( part.at( pos + 1 ) ==
'\n' || part.at( pos + 1 ) ==
'\r' ) )
113 if ( part.at( pos + 1 ) ==
'\r' ) pos++;
121 const QByteArray
headers = part.left( pos );
124 const QStringList headerRows = QString(
headers ).split( QRegularExpression(
"[\n\r]+" ) );
125 const auto constHeaderRows = headerRows;
126 for (
const QString &row : constHeaderRows )
129 const QStringList kv = row.split( QStringLiteral(
": " ) );
130 headersMap.insert( kv.value( 0 ).toLatin1(), kv.value( 1 ).toLatin1() );
132 mHeaders.append( headersMap );
134 mBodies.append( part.mid( pos ) );
136 from = to + boundary.length();