-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.h
50 lines (45 loc) · 1.03 KB
/
helpers.h
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
#ifndef HELPERS_H
#define HELPERS_H
#include <string>
#include <sstream>
class WebResource {
public:
std::string scheme;
std::string host;
int port;
std::string path;
std::string query;
WebResource()
: scheme()
, host()
, port(80)
, path("/")
, query()
{}
};
class HttpRequest {
public:
std::ostringstream request;
WebResource* resource;
HttpRequest(WebResource* rsc, const char* user_agent, bool robots = false)
: resource(rsc)
{
if (!robots) {
request << "GET " << rsc->path << rsc->query;
}
else {
request << "GET /robots.txt";
}
request << " HTTP/1.0" << "\r\n";
request << "User-agent: " << user_agent << "\r\n";
request << "Host: " << rsc->host << "\r\n";
request << "Connection: close" << "\r\n";
request << "\r\n";
}
std::string get_string() {
return request.str();
}
};
std::string http_request(WebResource* rsc, const char* user_agent, bool robots);
double diffclock(clock_t clock1,clock_t clock2);
#endif //HELPERS_H