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) {
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",
131 status_code::request_entity_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",
154 status_code::internal_server_error);
156 throw exception(
"Unexpected body encoding",
157 status_code::internal_server_error);
162 std::string::iterator end)
164 std::string::iterator cursor = std::search(
172 throw exception(
"Invalid header line",status_code::bad_request);
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";
header_list const & get_headers() const
Return a list of all HTTP headers.
size_t process_body(char const *buf, size_t len)
Process body data.
bool get_header_as_plist(std::string const &key, parameter_list &out) const
Extract an HTTP parameter list from a parser header.
void process_header(std::string::iterator begin, std::string::iterator end)
Process a header line.
void set_version(std::string const &version)
Set HTTP parser Version.
void remove_header(std::string const &key)
Remove a header from the parser.
void set_body(std::string const &value)
Set body content.
bool prepare_body()
Prepare the parser to begin parsing body data.
void replace_header(std::string const &key, std::string const &val)
Set a value for an HTTP header, replacing an existing value.
void append_header(std::string const &key, std::string const &val)
Append a value to an existing HTTP header.
std::string raw_headers() const
Generate and return the HTTP headers as a string.
std::string const & get_header(std::string const &key) const
Get the value of an HTTP header.
bool parse_parameter_list(std::string const &in, parameter_list &out) const
Extract an HTTP parameter list from a string.
static char const header_separator[]
Literal value of the HTTP header separator.
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list.
bool is_not_token_char(unsigned char c)
Is the character a non-token.
static std::string const empty_header
Literal value of an empty header.
Namespace for the WebSocket++ project.