summaryrefslogtreecommitdiff
path: root/http.h
blob: 29add9a60d8c365e57e17e950d469994478b842e (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
#ifndef HTTP_H
#define HTTP_H

#include <boost/asio.hpp>

#include <iostream>
#include <string>
#include <map>

typedef std::map<std::string, std::string> stringmap;
typedef stringmap HTTPHeaders;
typedef stringmap HTTPQuery;

class HTTPRequest {
	public:
		std::string type, path, httpver;
		HTTPQuery query;
		HTTPHeaders headers;
		HTTPRequest(std::istream& is);
		static void url_decode(std::string& str);
};

class HTTPResponse {
	private:
		HTTPHeaders headers;
		boost::asio::ip::tcp::socket& socket;
		void write_headers();
		bool headers_written;
	public:
		int code;
		std::string httpver, status;
		HTTPResponse(boost::asio::ip::tcp::socket& socket_);
		void add_header(std::string key, std::string value);
		void write(char *data, unsigned int len);
		void write(std::string str);
};

#endif