]> git.sur5r.net Git - minitube/blob - src/http/src/cachedhttp.h
Update watch file to use releases instead of tags
[minitube] / src / http / src / cachedhttp.h
1 #ifndef CACHEDHTTP_H
2 #define CACHEDHTTP_H
3
4 #include "http.h"
5
6 class LocalCache;
7
8 class CachedHttp : public Http {
9 public:
10     CachedHttp(Http &http = Http::instance(), const char *name = "http");
11     void setMaxSeconds(uint seconds);
12     void setMaxSize(uint maxSize);
13     void setCachePostRequests(bool value) { cachePostRequests = value; }
14     QObject *request(const HttpRequest &req);
15
16 private:
17     Http &http;
18     LocalCache *cache;
19     bool cachePostRequests;
20 };
21
22 class CachedHttpReply : public HttpReply {
23     Q_OBJECT
24
25 public:
26     CachedHttpReply(const QByteArray &body, const HttpRequest &req);
27     QUrl url() const { return req.url; }
28     int statusCode() const { return 200; }
29     QByteArray body() const;
30
31 private slots:
32     void emitSignals();
33
34 private:
35     const QByteArray bytes;
36     const HttpRequest &req;
37 };
38
39 class WrappedHttpReply : public QObject {
40     Q_OBJECT
41
42 public:
43     WrappedHttpReply(LocalCache *cache, const QByteArray &key, QObject *httpReply);
44
45 signals:
46     void data(const QByteArray &bytes);
47     void error(const QString &message);
48     void finished(const HttpReply &reply);
49
50 private slots:
51     void originFinished(const HttpReply &reply);
52
53 private:
54     LocalCache *cache;
55     QByteArray key;
56     QObject *httpReply;
57 };
58
59 #endif // CACHEDHTTP_H