forked from jgarzik/rpcsrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.h
80 lines (65 loc) · 1.59 KB
/
request.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// request.hpp
// ~~~~~~~~~~~
//
// Copyright 2012 Red Hat, Inc.
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef HTTP_SERVER3_REQUEST_HPP
#define HTTP_SERVER3_REQUEST_HPP
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "header.h"
namespace http {
namespace server3 {
/// A request received from a client.
struct request
{
std::string method;
std::string uri;
int http_version_major;
int http_version_minor;
std::vector<header> headers;
std::string content;
boost::posix_time::ptime tstamp;
void clear() {
method.clear();
uri.clear();
http_version_major = 0;
http_version_minor = 0;
headers.clear();
content.clear();
}
std::string get_header(std::string name) {
std::vector<header>::iterator hi;
for (hi = headers.begin(); hi != headers.end();hi++) {
if ((*hi).name == name)
return (*hi).value;
}
return "";
}
bool is_http11() const {
if ((http_version_major > 1) ||
((http_version_major == 1) && (http_version_minor > 0)))
return true;
return false;
}
bool want_keepalive() {
bool rc = is_http11();
std::string cxn_hdr =
boost::to_lower_copy(get_header("connection"));
if (cxn_hdr == "close")
rc = false;
else if (cxn_hdr == "keep-alive")
rc = true;
return rc;
}
};
} // namespace server3
} // namespace http
#endif // HTTP_SERVER3_REQUEST_HPP