This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httputils.cpp
73 lines (60 loc) · 1.8 KB
/
httputils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "httputils.h"
#include "cachedhttp.h"
#include "constants.h"
#include "http.h"
#include "localcache.h"
#include "throttledhttp.h"
Http &HttpUtils::notCached() {
static Http *h = [] {
Http *http = new Http;
http->addRequestHeader("User-Agent", userAgent());
return http;
}();
return *h;
}
Http &HttpUtils::cached() {
static Http *h = [] {
Http *http = new Http;
http->addRequestHeader("User-Agent", userAgent());
CachedHttp *cachedHttp = new CachedHttp(*http, "http");
return cachedHttp;
}();
return *h;
}
Http &HttpUtils::yt() {
static Http *h = [] {
Http *http = new Http;
http->addRequestHeader("User-Agent", stealthUserAgent());
CachedHttp *cachedHttp = new CachedHttp(*http, "yt");
cachedHttp->setMaxSeconds(3600);
return cachedHttp;
}();
return *h;
}
Http &HttpUtils::stealthAndNotCached() {
static Http *h = [] {
Http *http = new Http;
http->addRequestHeader("User-Agent", stealthUserAgent());
return http;
}();
return *h;
}
void HttpUtils::clearCaches() {
LocalCache::instance("yt")->clear();
LocalCache::instance("http")->clear();
}
const QByteArray &HttpUtils::userAgent() {
static const QByteArray ua = [] {
return QString(QLatin1String(Constants::NAME) + QLatin1Char('/') +
QLatin1String(Constants::VERSION) + QLatin1String(" ( ") +
Constants::WEBSITE + QLatin1String(" )"))
.toUtf8();
}();
return ua;
}
const QByteArray &HttpUtils::stealthUserAgent() {
static const QByteArray ua =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like "
"Gecko) Chrome/79.0.3945.79 Safari/537.36";
return ua;
}