summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/httpget.h
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/base/httpget.h')
-rw-r--r--rbutil/rbutilqt/base/httpget.h80
1 files changed, 46 insertions, 34 deletions
diff --git a/rbutil/rbutilqt/base/httpget.h b/rbutil/rbutilqt/base/httpget.h
index 73d3fbbaf5..2f6448a40d 100644
--- a/rbutil/rbutilqt/base/httpget.h
+++ b/rbutil/rbutilqt/base/httpget.h
@@ -24,6 +24,7 @@
24 24
25#include <QtCore> 25#include <QtCore>
26#include <QtNetwork> 26#include <QtNetwork>
27#include <QNetworkAccessManager>
27 28
28class HttpGet : public QObject 29class HttpGet : public QObject
29{ 30{
@@ -42,14 +43,34 @@ class HttpGet : public QObject
42 int httpResponse(void); 43 int httpResponse(void);
43 QByteArray readAll(void); 44 QByteArray readAll(void);
44 bool isCached() 45 bool isCached()
45 { return m_cached; } 46 { return m_lastRequestCached; }
46 QDateTime timestamp(void) 47 QDateTime timestamp(void)
47 { return m_serverTimestamp; } 48 { return m_lastServerTimestamp; }
48 static void setGlobalCache(const QDir& d) //< set global cache path 49 //< set global cache path
49 { m_globalCache = d; } 50 static void setGlobalCache(const QDir& d)
50 static void setGlobalProxy(const QUrl& p) //< set global proxy value 51 {
51 { m_globalProxy = p; } 52 qDebug() << "[HttpGet] Global cache set to" << d.absolutePath();
52 static void setGlobalUserAgent(const QString& u) //< set global user agent string 53 m_globalCache = d;
54 }
55 //< set global proxy value
56 static void setGlobalProxy(const QUrl& p)
57 {
58 qDebug() << "[HttpGet] setting global proxy" << p;
59 if(!p.isValid() || p.isEmpty()) {
60 HttpGet::m_globalProxy.setType(QNetworkProxy::NoProxy);
61 }
62 else {
63 HttpGet::m_globalProxy.setType(QNetworkProxy::HttpProxy);
64 HttpGet::m_globalProxy.setHostName(p.host());
65 HttpGet::m_globalProxy.setPort(p.port());
66 HttpGet::m_globalProxy.setUser(p.userName());
67 HttpGet::m_globalProxy.setPassword(p.password());
68 }
69 QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
70 QNetworkProxy::setApplicationProxy(HttpGet::m_globalProxy);
71 }
72 //< set global user agent string
73 static void setGlobalUserAgent(const QString& u)
53 { m_globalUserAgent = u; } 74 { m_globalUserAgent = u; }
54 75
55 public slots: 76 public slots:
@@ -62,37 +83,28 @@ class HttpGet : public QObject
62 void headerFinished(void); 83 void headerFinished(void);
63 84
64 private slots: 85 private slots:
65 void httpDone(bool error); 86 void requestFinished(QNetworkReply* reply);
66 void httpFinished(int, bool); 87 void startRequest(QUrl url);
67 void httpResponseHeader(const QHttpResponseHeader&); 88 void downloadProgress(qint64 received, qint64 total);
68 void httpState(int); 89 void networkError(QNetworkReply::NetworkError error);
69 void httpStarted(int);
70 void getFileFinish(void);
71 90
72 private: 91 private:
73 bool initializeCache(const QDir&); 92 static QString m_globalUserAgent;
74 QHttp http; //< download object 93 static QNetworkProxy m_globalProxy;
75 QFile *outputFile; 94 QNetworkAccessManager *m_mgr;
76 int m_response; //< http response 95 QNetworkReply *m_reply;
77 int getRequest; //! get file http request id 96 QNetworkDiskCache *m_cache;
78 int headRequest; //! get http header request id
79 QByteArray dataBuffer;
80 bool outputToBuffer;
81 bool m_usecache;
82 QDir m_cachedir; 97 QDir m_cachedir;
83 QString m_cachefile; // cached filename
84 bool m_cached;
85 QUrl m_proxy;
86 bool m_useproxy;
87 QDateTime m_serverTimestamp; //< timestamp of file on server
88 QString m_query; //< constructed query to pass http getter
89 QString m_path; //< constructed path to pass http getter
90 QString m_hash; //< caching hash
91 QHttpRequestHeader m_header;
92
93 static QDir m_globalCache; //< global cache path value 98 static QDir m_globalCache; //< global cache path value
94 static QUrl m_globalProxy; //< global proxy value 99 QByteArray m_data;
95 static QString m_globalUserAgent; //< global user agent string 100 QFile *m_outputFile;
101 int m_lastStatusCode;
102 QString m_lastErrorString;
103 QDateTime m_lastServerTimestamp;
104 bool m_lastRequestCached;
105 QNetworkProxy m_proxy;
96}; 106};
97 107
108
98#endif 109#endif
110