-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathproxy.cpp
53 lines (49 loc) · 1.19 KB
/
proxy.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
#include <iostream>
#include "ProxyException.h"
#include "ProxyController.h"
#include "ProxyHeaders.h"
#include <boost/thread.hpp>
static boost::mutex callback_mu;
void onrequest(const char* data, size_t len)
{
callback_mu.lock();
RequestHeader rh;
rh.Parse(data, len);
std::cout << "> " << rh.method << " " << rh.uri.ToString(true) << std::endl;
callback_mu.unlock();
}
void onresponse(const char* data, size_t len)
{
callback_mu.lock();
ResponseHeader rh;
rh.Parse(data, len);
std::cout << "< " << rh.code << std::endl;
callback_mu.unlock();
}
int main()
{
try
{
std::cout << "Proxy run" << std::endl;
ProxyController &pc = ProxyController::GetController();
pc.SetRequestCallback(&onrequest);
pc.SetResponseCallback(&onresponse);
pc.Start(8080);
std::string input;
while(input == "")
{
std::cin >> input;
}
pc.Stop();
std::cout << "Stoped" << std::endl;
return 0;
}
catch(ProxyException e)
{
std::cout << "Fatal error: " << e.what() << std::endl;
}
catch(...)
{
std::cout << "Other error!" << std::endl;
}
}