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;
55 m_buf->append(buf,len);
58 std::string::iterator begin = m_buf->begin();
59 std::string::iterator end;
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)
108 bytes_processed +=
process_body(buf+bytes_processed,len-bytes_processed);
112 return bytes_processed;
117 return bytes_processed;
120 if (m_method.empty()) {
121 this->process(begin,end);
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()) {
164 inline 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));
191 #endif // HTTP_PARSER_REQUEST_IMPL_HPP std::string const & get_header(std::string const &key) const
Get the value of an HTTP header.
static char const header_delimiter[]
Literal value of the HTTP header delimiter.
size_t m_body_bytes_needed
size_t process_body(char const *buf, size_t len)
Process body data.
bool is_not_token_char(unsigned char c)
Is the character a non-token.
bool prepare_body()
Prepare the parser to begin parsing body data.
void process_header(std::string::iterator begin, std::string::iterator end)
Process a header line.
std::string raw_headers() const
Generate and return the HTTP headers as a string.
std::string const & get_version() const
Get the HTTP version string.
Namespace for the WebSocket++ project.
size_t const max_header_size
Maximum size in bytes before rejecting an HTTP header as too big.
std::string raw_head() const
Returns the raw request headers only (similar to an HTTP HEAD request)
void set_uri(std::string const &uri)
Set the HTTP uri. Must be a valid HTTP uri.
void set_version(std::string const &version)
Set HTTP parser Version.
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
void set_method(std::string const &method)
Set the HTTP method. Must be a valid HTTP token.
bool body_ready() const
Check if the parser is done parsing the body.
std::string raw() const
Returns the full raw request (including the body)