33 if ( !mReply )
return;
41 QMap<QByteArray, QByteArray>
headers;
42 const auto constRawHeaderList = mReply->rawHeaderList();
43 for (
const QByteArray &h : constRawHeaderList )
45 headers.insert( h, mReply->rawHeader( h ) );
48 mBodies.append( mReply->readAll() );
52 const QString contentType = mReply->header( QNetworkRequest::ContentTypeHeader ).toString();
55 const thread_local QRegularExpression re(
".*boundary=\"?([^\"]+)\"?\\s?", QRegularExpression::CaseInsensitiveOption );
56 const QRegularExpressionMatch match = re.match( contentType );
57 if ( !( match.capturedStart( 0 ) == 0 ) )
59 mError = tr(
"Cannot find boundary in multipart content type" );
63 QString boundary = match.captured( 1 );
64 QgsDebugMsgLevel( QStringLiteral(
"boundary = %1 size = %2" ).arg( boundary ).arg( boundary.size() ), 2 );
65 boundary =
"--" + boundary;
68 const QByteArray data = mReply->readAll();
70 from = data.indexOf( boundary.toLatin1(), 0 ) + boundary.length() + 1;
76 to = data.indexOf( boundary.toLatin1(), from );
79 QgsDebugMsgLevel( QStringLiteral(
"No more boundaries, rest size = %1" ).arg( data.size() - from - 1 ), 2 );
81 if ( data.size() - from - 1 == 2 && QString( data.mid( from, 2 ) ) == QLatin1String(
"--" ) )
88 if ( data.size() - from > 1 )
97 QgsDebugMsgLevel( QStringLiteral(
"part %1 - %2" ).arg( from ).arg( to ), 2 );
98 QByteArray part = data.mid( from, to - from );
100 while ( !part.isEmpty() && ( part.at( 0 ) ==
'\r' || part.at( 0 ) ==
'\n' ) )
107 while ( pos < part.size() - 1 )
109 if ( part.at( pos ) ==
'\n' && ( part.at( pos + 1 ) ==
'\n' || part.at( pos + 1 ) ==
'\r' ) )
111 if ( part.at( pos + 1 ) ==
'\r' ) pos++;
119 const QByteArray
headers = part.left( pos );
122 const QStringList headerRows = QString(
headers ).split( QRegularExpression(
"[\n\r]+" ) );
123 const auto constHeaderRows = headerRows;
124 for (
const QString &row : constHeaderRows )
127 const QStringList kv = row.split( QStringLiteral(
": " ) );
128 headersMap.insert( kv.value( 0 ).toLatin1(), kv.value( 1 ).toLatin1() );
130 mHeaders.append( headersMap );
132 mBodies.append( part.mid( pos ) );
134 from = to + boundary.length();