36 if ( !mReply )
return;
44 QMap<QByteArray, QByteArray>
headers;
45 const auto constRawHeaderList = mReply->rawHeaderList();
46 for (
const QByteArray &h : constRawHeaderList )
48 headers.insert( h, mReply->rawHeader( h ) );
51 mBodies.append( mReply->readAll() );
55 const QString contentType = mReply->header( QNetworkRequest::ContentTypeHeader ).toString();
58 const thread_local QRegularExpression re(
".*boundary=\"?([^\"]+)\"?\\s?", QRegularExpression::CaseInsensitiveOption );
59 const QRegularExpressionMatch match = re.match( contentType );
60 if ( !( match.capturedStart( 0 ) == 0 ) )
62 mError = tr(
"Cannot find boundary in multipart content type" );
66 QString boundary = match.captured( 1 );
67 QgsDebugMsgLevel( u
"boundary = %1 size = %2"_s.arg( boundary ).arg( boundary.size() ), 2 );
68 boundary =
"--" + boundary;
71 const QByteArray data = mReply->readAll();
73 from = data.indexOf( boundary.toLatin1(), 0 ) + boundary.length() + 1;
79 to = data.indexOf( boundary.toLatin1(), from );
82 QgsDebugMsgLevel( u
"No more boundaries, rest size = %1"_s.arg( data.size() - from - 1 ), 2 );
84 if ( data.size() - from - 1 == 2 && QString( data.mid( from, 2 ) ) ==
"--"_L1 )
91 if ( data.size() - from > 1 )
101 QByteArray part = data.mid( from, to - from );
103 while ( !part.isEmpty() && ( part.at( 0 ) ==
'\r' || part.at( 0 ) ==
'\n' ) )
110 while ( pos < part.size() - 1 )
112 if ( part.at( pos ) ==
'\n' && ( part.at( pos + 1 ) ==
'\n' || part.at( pos + 1 ) ==
'\r' ) )
114 if ( part.at( pos + 1 ) ==
'\r' ) pos++;
122 const QByteArray
headers = part.left( pos );
125 const QStringList headerRows = QString(
headers ).split( QRegularExpression(
"[\n\r]+" ) );
126 const auto constHeaderRows = headerRows;
127 for (
const QString &row : constHeaderRows )
130 const QStringList kv = row.split( u
": "_s );
131 headersMap.insert( kv.value( 0 ).toLatin1(), kv.value( 1 ).toLatin1() );
133 mHeaders.append( headersMap );
135 mBodies.append( part.mid( pos ) );
137 from = to + boundary.length();