OSDN Git Service

Refactoring HTTP parser.
[ultramonkey-l7/sslproxy.git] / include / http_message.h
1 /*
2  * @file  http_message.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 __HTTP_MESSAGE_H__
25 #define __HTTP_MESSAGE_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 <boost/algorithm/string.hpp>
32 #include <boost/algorithm/string/detail/case_conv.hpp>
33 #include <boost/tokenizer.hpp>
34 #include <string>
35 #include "http_message_enum.h"
36 #include "logger_wrapper.h"
37
38 using boost::multi_index_container;
39 using namespace boost::multi_index;
40
41 struct field_map; // tag
42 typedef std::pair<std::string, std::string> field; // header field
43 typedef multi_index_container<
44   field,
45   indexed_by<
46     sequenced<>, // header field order
47     hashed_non_unique< tag<field_map>, member<field, std::string, &field::first> >
48   >
49 > header_container;
50 typedef header_container::index_iterator<field_map>::type field_map_iterator;
51 typedef std::pair<field_map_iterator, field_map_iterator> field_range;
52
53 //! HTTP Message Class (RFC2616)
54 class http_message
55 {
56 protected:
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     _body;
68     std::string     incomplete;
69     std::string     raw_message;
70     bool            modified;
71     std::string convert_upper_camel_case(std::string);
72
73 public:
74     http_message();
75     http_message( std::string );
76     ~http_message();
77
78     field_range header( std::string );
79     void header( std::string, std::string );
80     std::string body();
81     std::string body( std::string );
82
83     std::string as_string();
84     void parse( std::string );
85     void rebuild();
86 };
87
88 #endif //__HTTP_MESSAGE_H__