28 #ifndef HTTP_PARSER_IMPL_HPP
29 #define HTTP_PARSER_IMPL_HPP
46 header_list::const_iterator h = m_headers.find(key);
48 if (h == m_headers.end()) {
58 header_list::const_iterator it = m_headers.find(key);
60 if (it == m_headers.end() || it->second.size() == 0) {
64 return this->parse_parameter_list(it->second,out);
71 throw exception(
"Invalid header name",
status_code::bad_request);
77 m_headers[key] +=
", " + val;
92 if (value.size() == 0) {
101 std::stringstream len;
110 if (in.size() == 0) {
114 std::string::const_iterator it;
115 it = extract_parameters(in.begin(),in.end(),out);
116 return (it == in.begin());
121 std::string
const & cl_header =
get_header(
"Content-Length");
127 m_body_bytes_needed = std::strtoul(cl_header.c_str(),&end,10);
129 if (m_body_bytes_needed > m_body_bytes_max) {
130 throw exception(
"HTTP message body too large",
134 m_body_encoding = body_encoding::plain;
136 }
else if (
get_header(
"Transfer-Encoding") ==
"chunked") {
146 if (m_body_encoding == body_encoding::plain) {
147 size_t processed = (std::min)(m_body_bytes_needed,len);
148 m_body.append(buf,processed);
149 m_body_bytes_needed -= processed;
151 }
else if (m_body_encoding == body_encoding::chunked) {
153 throw exception(
"Unexpected body encoding",
156 throw exception(
"Unexpected body encoding",
162 std::string::iterator end)
164 std::string::iterator cursor = std::search(
168 header_separator +
sizeof(header_separator) - 1
172 throw exception(
"Invalid header line",
status_code::bad_request);
175 append_header(strip_lws(std::string(begin,cursor)),
176 strip_lws(std::string(cursor+
sizeof(header_separator)-1,end)));
184 std::stringstream raw;
186 header_list::const_iterator it;
187 for (it = m_headers.begin(); it != m_headers.end(); it++) {
188 raw << it->first <<
": " << it->second <<
"\r\n";