22 #include <QNetworkReply>
26 #include <QStringList>
41 QMap<QByteArray, QByteArray>
headers;
42 foreach ( QByteArray h,
mReply->rawHeaderList() )
44 headers.insert( h,
mReply->rawHeader( h ) );
51 QString contentType =
mReply->header( QNetworkRequest::ContentTypeHeader ).toString();
54 QRegExp re(
".*boundary=\"?([^\"]+)\"?\\s?", Qt::CaseInsensitive );
56 if ( !re.indexIn( contentType ) == 0 )
58 mError =
tr(
"Cannot find boundary in multipart content type" );
62 QString boundary = re.cap( 1 );
63 QgsDebugMsg( QString(
"boundary = %1 size = %2" ).arg( boundary ).arg( boundary.size() ) );
64 boundary =
"--" + boundary;
67 QByteArray data =
mReply->readAll();
69 from = data.indexOf( boundary.toAscii(), 0 ) + boundary.length() + 1 ;
75 to = data.indexOf( boundary.toAscii(), from );
78 QgsDebugMsg( QString(
"No more boundaries, rest size = %1" ).arg( data.size() - from - 1 ) );
80 if ( data.size() - from - 1 == 2 && QString( data.mid( from, 2 ) ) ==
"--" )
87 if ( data.size() - from > 1 )
96 QgsDebugMsg( QString(
"part %1 - %2" ).arg( from ).arg( to ) );
97 QByteArray part = data.mid( from, to - from );
99 while ( part.size() > 0 && ( part.at( 0 ) ==
'\r' || part.at( 0 ) ==
'\n' ) )
106 while ( pos < part.size() - 1 )
108 if ( part.at( pos ) ==
'\n' && ( part.at( pos + 1 ) ==
'\n' || part.at( pos + 1 ) ==
'\r' ) )
110 if ( part.at( pos + 1 ) ==
'\r' ) pos++;
118 QByteArray
headers = part.left( pos );
121 QStringList headerRows = QString( headers ).split( QRegExp(
"[\n\r]+" ) );
122 foreach ( QString row, headerRows )
125 QStringList kv = row.split(
": " );
126 headersMap.insert( kv.value( 0 ).toAscii(), kv.value( 1 ).toAscii() );
130 mBodies.append( part.mid( pos ) );
132 from = to + boundary.length();
140 if ( !reply )
return false;
142 QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
148 return contentType.startsWith(
"multipart/", Qt::CaseInsensitive );