Mercurial > hg > svcore
comparison data/fileio/FileSource.cpp @ 496:05383ee78f3e
* Support http redirects
author | Chris Cannam |
---|---|
date | Thu, 27 Nov 2008 22:09:58 +0000 |
parents | dddd4ab77068 |
children | b6dc6c7f402c |
comparison
equal
deleted
inserted
replaced
495:438f4e295a9c | 496:05383ee78f3e |
---|---|
27 #include <QHttpResponseHeader> | 27 #include <QHttpResponseHeader> |
28 | 28 |
29 #include <iostream> | 29 #include <iostream> |
30 #include <cstdlib> | 30 #include <cstdlib> |
31 | 31 |
32 //#define DEBUG_FILE_SOURCE 1 | 32 #define DEBUG_FILE_SOURCE 1 |
33 | 33 |
34 int | 34 int |
35 FileSource::m_count = 0; | 35 FileSource::m_count = 0; |
36 | 36 |
37 QMutex | 37 QMutex |
544 | 544 |
545 void | 545 void |
546 FileSource::httpResponseHeaderReceived(const QHttpResponseHeader &resp) | 546 FileSource::httpResponseHeaderReceived(const QHttpResponseHeader &resp) |
547 { | 547 { |
548 m_lastStatus = resp.statusCode(); | 548 m_lastStatus = resp.statusCode(); |
549 if (m_lastStatus / 100 == 3) { | |
550 QString location = resp.value("Location"); | |
551 #ifdef DEBUG_FILE_SOURCE | |
552 std::cerr << "FileSource::responseHeaderReceived: redirect to \"" | |
553 << location.toStdString() << "\" received" << std::endl; | |
554 #endif | |
555 if (location != "") { | |
556 QUrl newUrl(location); | |
557 if (newUrl != m_url) { | |
558 m_url = newUrl; | |
559 m_lastStatus = 0; | |
560 disconnect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); | |
561 disconnect(m_http, SIGNAL(dataReadProgress(int, int)), | |
562 this, SLOT(dataReadProgress(int, int))); | |
563 m_http->abort(); | |
564 m_http->deleteLater(); | |
565 m_http = 0; | |
566 init(); | |
567 return; | |
568 } | |
569 } | |
570 } | |
549 if (m_lastStatus / 100 >= 4) { | 571 if (m_lastStatus / 100 >= 4) { |
550 m_errorString = QString("%1 %2") | 572 m_errorString = QString("%1 %2") |
551 .arg(resp.statusCode()).arg(resp.reasonPhrase()); | 573 .arg(resp.statusCode()).arg(resp.reasonPhrase()); |
552 #ifdef DEBUG_FILE_SOURCE | 574 #ifdef DEBUG_FILE_SOURCE |
553 std::cerr << "FileSource::responseHeaderReceived: " | 575 std::cerr << "FileSource::responseHeaderReceived: " |