OSDN Git Service

Temporary implementation of insert X-Forwarded-For.
[ultramonkey-l7/sslproxy.git] / include / httprequest.h
1 /*
2  * @file  httprequest.h
3  * @brief HTTP Request Message Header
4  *
5  * Copyright (C) 2009  NTT COMWARE Corporation.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  **********************************************************************/
23
24 #ifndef __HTTPREQUEST_H__
25 #define __HTTPREQUEST_H__
26
27 #include <boost/multi_index_container.hpp>
28 #include <boost/multi_index/member.hpp>
29 #include <boost/multi_index/hashed_index.hpp>
30 #include <boost/multi_index/sequenced_index.hpp>
31 #include <string>
32 #include "httprequest_enum.h"
33 #include "logger_wrapper.h"
34
35 using boost::multi_index_container;
36 using namespace boost::multi_index;
37
38 struct field_map; // tag
39 typedef std::pair<std::string, std::string> field; // header field
40 typedef multi_index_container<
41   field,
42   indexed_by<
43     sequenced<>, // header field order
44     hashed_non_unique< tag<field_map>, member<field, std::string, &field::first> >
45   >
46 > header_container;
47 typedef header_container::index_iterator<field_map>::type field_map_iterator;
48 typedef std::pair<field_map_iterator, field_map_iterator> field_range;
49
50 //! HTTP Request Class (RFC2616)
51 class http_request
52 {
53 protected:
54     std::string         _method;
55     std::string         _request_uri;
56     std::string         _http_version;
57     /*
58      * _header : keep header fields order and fast key lookup.
59      *
60      * RFC2616 Sec 4.2
61      * The order in which header fields with the same field-name are
62      * received is therefore significant to the interpretation of
63      * the combined field value, and thus a proxy MUST NOT change
64      * the order of these field values when a message is forwarded.
65      */
66     header_container    _header;
67     std::string     _message;
68     std::string     incomplete;
69     std::string     raw_request;
70     bool            modified;
71
72 public:
73     http_request();
74     http_request( std::string );
75     ~http_request();
76
77     std::string method();
78     std::string method( std::string );
79     std::string request_uri();
80     std::string request_uri( std::string );
81     std::string http_version();
82     std::string http_version( std::string );
83     field_range header( std::string );
84     void header( std::string, std::string );
85     std::string message();
86     std::string message( std::string );
87
88     std::string request_line();
89     std::string as_string();
90     void parse( std::string );
91     void rebuild();
92 };
93
94 #endif //__HTTPREQUEST_H__