28#ifndef HTTP_PARSER_REQUEST_IMPL_HPP
29#define HTTP_PARSER_REQUEST_IMPL_HPP
42 size_t bytes_processed;
44 if (m_ready) {
return 0;}
51 return bytes_processed;
58 std::string::iterator begin = m_buf->begin();
59 std::string::iterator end;
67 header_delimiter+
sizeof(header_delimiter)-1
74 throw exception(
"Maximum header size exceeded.",
78 if (end == m_buf->end()) {
81 std::copy(begin,end,m_buf->begin());
82 m_buf->resize(
static_cast<std::string::size_type
>(end-begin));
91 if (m_method.empty() ||
get_header(
"Host").empty()) {
96 len -
static_cast<std::string::size_type
>(m_buf->end()-end)
97 +
sizeof(header_delimiter) - 1
112 return bytes_processed;
117 return bytes_processed;
120 if (m_method.empty()) {
121 this->process(begin,end);
127 begin = end+(
sizeof(header_delimiter)-1);
133 std::stringstream
ret;
135 ret << m_method <<
" " << m_uri <<
" " <<
get_version() <<
"\r\n";
143 std::stringstream
ret;
145 ret << m_method <<
" " << m_uri <<
" " <<
get_version() <<
"\r\n";
152 if (std::find_if(method.begin(),method.end(),
is_not_token_char) != method.end()) {
164inline void request::process(std::string::iterator begin, std::string::iterator
167 std::string::iterator cursor_start = begin;
168 std::string::iterator cursor_end = std::find(begin,end,
' ');
170 if (cursor_end == end) {
174 set_method(std::string(cursor_start,cursor_end));
176 cursor_start = cursor_end+1;
177 cursor_end = std::find(cursor_start,end,
' ');
179 if (cursor_end == end) {
183 set_uri(std::string(cursor_start,cursor_end));
size_t process_body(char const *buf, size_t len)
Process body data.
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.
bool body_ready() const
Check if the parser is done parsing the body.
size_t m_body_bytes_needed
bool prepare_body()
Prepare the parser to begin parsing body data.
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.
std::string const & get_version() const
Get the HTTP version string.
std::string raw() const
Returns the full raw request (including the body)
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
void set_uri(std::string const &uri)
Set the HTTP uri. Must be a valid HTTP uri.
void set_method(std::string const &method)
Set the HTTP method. Must be a valid HTTP token.
std::string raw_head() const
Returns the raw request headers only (similar to an HTTP HEAD request)
@ request_header_fields_too_large
bool is_not_token_char(unsigned char c)
Is the character a non-token.
size_t const max_header_size
Maximum size in bytes before rejecting an HTTP header as too big.
Namespace for the WebSocket++ project.