-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy_handler.hpp
65 lines (50 loc) · 2.04 KB
/
proxy_handler.hpp
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
#ifndef PROXY_HANDLER_HPP
#define PROXY_HANDLER_HPP
#include <string>
#include <vector>
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include "request.hpp"
#include "response.hpp"
#include "request_handler.hpp"
typedef std::vector<std::pair<std::string, std::string>> Headers;
namespace http {
namespace server {
class ProxyHandler : public RequestHandler
{
std::string uri_prefix_;
std::string remote_host_whole_url;
std::string protocol_;
std::string host_url_;
std::string path_;
std::string response_headers, response_body, response_status, rest;
Headers headers_;
std::string remote_port_;
bool url_decode(const std::string& in, std::string& out);
bool parse_remote_url(std::string remote_host_url);
bool parse_remote_response(std::string remote_response);
bool read_header(std::string headers);
public:
//static_handler(std::string root);
// virtual ~static_handler() {}
//virtual bool handle_request(const request& request_, reply& reply_);
// Initializes the handler. Returns a response code indicating success or
// failure condition.
// uri_prefix is the value in the config file that this handler will run for.
// config is the contents of the child block for this handler ONLY.
virtual Status Init(const std::string& uri_prefix, const NginxConfig& config);
// Handles an HTTP request, and generates a response. Returns a response code
// indicating success or failure condition. If ResponseCode is not OK, the
// contents of the response object are undefined, and the server will return
// HTTP code 500.
virtual Status HandleRequest(const Request& request, Response* response);
std::string getPrefix();
std::string getWholeURL();
std::string getProtocol();
std::string getHostURL();
std::string getPath();
};
REGISTER_REQUEST_HANDLER(ProxyHandler);
} // namespace server
} // namespace http
#endif // PROXY_HANDLER_HPP