34 if ( !mReply )
return;
42 QMap<QByteArray, QByteArray>
headers;
43 const auto constRawHeaderList = mReply->rawHeaderList();
44 for (
const QByteArray &h : constRawHeaderList )
46 headers.insert( h, mReply->rawHeader( h ) );
49 mBodies.append( mReply->readAll() );
53 const QString contentType = mReply->header( QNetworkRequest::ContentTypeHeader ).toString();
56 const thread_local QRegularExpression re(
".*boundary=\"?([^\"]+)\"?\\s?", QRegularExpression::CaseInsensitiveOption );
57 const QRegularExpressionMatch match = re.match( contentType );
58 if ( !( match.capturedStart( 0 ) == 0 ) )
60 mError = tr(
"Cannot find boundary in multipart content type" );
64 QString boundary = match.captured( 1 );
65 QgsDebugMsgLevel( QStringLiteral(
"boundary = %1 size = %2" ).arg( boundary ).arg( boundary.size() ), 2 );
66 boundary =
"--" + boundary;
69 const QByteArray data = mReply->readAll();
71 from = data.indexOf( boundary.toLatin1(), 0 ) + boundary.length() + 1;
77 to = data.indexOf( boundary.toLatin1(), from );
80 QgsDebugMsgLevel( QStringLiteral(
"No more boundaries, rest size = %1" ).arg( data.size() - from - 1 ), 2 );
82 if ( data.size() - from - 1 == 2 && QString( data.mid( from, 2 ) ) == QLatin1String(
"--" ) )
89 if ( data.size() - from > 1 )
98 QgsDebugMsgLevel( QStringLiteral(
"part %1 - %2" ).arg( from ).arg( to ), 2 );
99 QByteArray part = data.mid( from, to - from );
101 while ( !part.isEmpty() && ( part.at( 0 ) ==
'\r' || part.at( 0 ) ==
'\n' ) )
108 while ( pos < part.size() - 1 )
110 if ( part.at( pos ) ==
'\n' && ( part.at( pos + 1 ) ==
'\n' || part.at( pos + 1 ) ==
'\r' ) )
112 if ( part.at( pos + 1 ) ==
'\r' ) pos++;
120 const QByteArray
headers = part.left( pos );
123 const QStringList headerRows = QString(
headers ).split( QRegularExpression(
"[\n\r]+" ) );
124 const auto constHeaderRows = headerRows;
125 for (
const QString &row : constHeaderRows )
128 const QStringList kv = row.split( QStringLiteral(
": " ) );
129 headersMap.insert( kv.value( 0 ).toLatin1(), kv.value( 1 ).toLatin1() );
131 mHeaders.append( headersMap );
133 mBodies.append( part.mid( pos ) );
135 from = to + boundary.length();