]> git.sur5r.net Git - minitube/blob - lib/http/src/cachedhttp.h
New upstream version 3.1
[minitube] / lib / 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     HttpReply *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 HttpReply {
40     Q_OBJECT
41
42 public:
43     WrappedHttpReply(LocalCache *cache, const QByteArray &key, HttpReply *httpReply);
44     QUrl url() const { return httpReply->url(); }
45     int statusCode() const { return httpReply->statusCode(); }
46     QByteArray body() const { return httpReply->body(); }
47
48 private slots:
49     void originFinished(const HttpReply &reply);
50
51 private:
52     LocalCache *cache;
53     QByteArray key;
54     HttpReply *httpReply;
55 };
56
57 #endif // CACHEDHTTP_H