blob: 6567f81b178d11823b624e025b0e81156dd21dcd (
plain)
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
|
#include "http_connection.h"
#include "http.h"
#include <boost/bind.hpp>
HTTP::Connection::Connection(boost::asio::io_service& io_service) : socket(io_service) {
}
void HTTP::Connection::handle_write(const boost::system::error_code& error, size_t bytes_transferred) {
}
void HTTP::Connection::handle_read(const boost::system::error_code& error, size_t bytes_transferred, Handler callback) {
if(!parse_request(buf)) {
// Request parse error.
std::cout << "Request parse error." << std::endl;
//return;
}
std::cout << "Path: " << std::endl;
for(PathList::iterator it = path.begin(); it != path.end(); it++) {
std::cout << " " << *it << std::endl;
}
std::cout << "Args: " << std::endl;
for(std::map<std::string, std::string>::iterator it = args.begin(); it != args.end(); it++) {
std::cout << " " << it->first << " = " << it->second << std::endl;
}
std::cout << "Headers: " << std::endl;
for(std::map<std::string, std::string>::iterator it = headers.begin(); it != headers.end(); it++) {
std::cout << " " << it->first << " = " << it->second << std::endl;
}
callback(shared_from_this());
}
void print(char c) {
std::cout << "Char: " << int(c) << std::endl;
}
void HTTP::Connection::read_request(Handler callback) {
boost::asio::async_read_until(socket, buf, "\r\n\r\n", boost::bind(&Connection::handle_read, shared_from_this(),
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, callback));
}
std::string HTTP::Connection::pop_path_base() {
if(!path.size()) {
return "";
}
base_path.push_back(path.front());
path.pop_front();
return base_path.back();
}
|