I subclass QNetworkAccessManager (This class was introduced in Qt 4.4.) to load remote xml html or image to compose documents.

the code is avaiable on:

http://fop-miniscribus.googlecode.co...rk/FillCache.h
http://fop-miniscribus.googlecode.co.../FillCache.cpp

I start request on this way:

Qt Code:
  1. void NetCacheSwap::start_Get( const QUrl url )
  2. {
  3. CacheInfo havingram = take_Url(url);
  4. if (havingram.pending) {
  5. /* request ist start */
  6. return;
  7. }
  8. if (havingram.valid) {
  9. /* request and data live on swap cache */
  10. emit incomming(url);
  11. return;
  12. }
  13. CacheInfo newrequest;
  14. QNetworkRequest need(url);
  15. need.setRawHeader( "User-Agent", "Mozilla/5.0 (X11; U; Linux i686 (x86_64); "
  16. "en-US; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1" );
  17. need.setRawHeader( "Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7" );
  18. need.setRawHeader( "Accept-Encoding", "gzip,deflate,qcompress" ); ////////gzip,deflate,qcompress
  19. need.setRawHeader( "Connection", "keep-alive" );
  20. if (cookie_host[url.host()].size() > 0) {
  21. qDebug() << "### > send cookie ->" << cookie_host[url.host()].toAscii();
  22. need.setRawHeader( "Cookie",cookie_host[url.host()].toAscii());
  23. }
  24. QNetworkReply *reps = get(need);
  25. /* mark it as pending request! */
  26. newrequest.pending = true;
  27. cache_ram.insert(fastmd5(url.toString()),newrequest);
  28. connect(reps, SIGNAL(downloadProgress (qint64,qint64)),
  29. SLOT(progress(qint64,qint64)));
  30. connect(reps, SIGNAL(error(QNetworkReply::NetworkError)),
  31. SLOT(url_error(QNetworkReply::NetworkError)));
  32. connect(reps, SIGNAL(finished()),SLOT(incomming_cache()));
  33. }
To copy to clipboard, switch view to plain text mode 

if incomming chunk is and header is content-encoding == gzip i open on this way:

i decompress on file .....
Qt Code:
  1. QByteArray NetCacheSwap::deflate( const QByteArray chunk )
  2. {
  3. QChar letter('A' + (qrand() % 26));
  4. /* must not go on file solution gunzip buffer ? go cache from net location */
  5. const QString tmpfiler = QString("%1/http_%2.gz").arg(location).arg(letter);
  6. QByteArray input;
  7. QFile file(tmpfiler);
  8. if ( file.open(QIODevice::WriteOnly) ) {
  9. file.write(chunk);
  10. file.close();
  11. gzFile filegunzip;
  12. filegunzip = gzopen(tmpfiler.toUtf8().data(),"rb");
  13. if(!filegunzip) {
  14. qDebug() << "### Unable to work on tmp file ... ";
  15. return QByteArray();
  16. }
  17. char buffer[1024];
  18. while(int readBytes =gzread(filegunzip, buffer, 1024))
  19. {
  20. input.append(QByteArray(buffer, readBytes));
  21. }
  22. gzclose(filegunzip);
  23. file.remove();
  24. }
  25. return input;
  26. }
To copy to clipboard, switch view to plain text mode 

How i can deflate / decompress QByteArray data direct on buffer? is this possibel?


i search "content-encoding" on network qt lib i found only

bool QHttpNetworkReplyPrivate::isGzipped()
{
QByteArray encoding = headerField("content-encoding");
return encoding.toLower() == "gzip";
}

and isGzipped search is NULL on other or webkit .. ?