28 #ifndef HTTP_PARSER_REQUEST_IMPL_HPP
29 #define HTTP_PARSER_REQUEST_IMPL_HPP
34 #include <websocketpp/http/parser.hpp>
46 if (req[req.size()-1] ==
'\r') {
47 req.erase(req.end()-1);
49 std::stringstream ss(req);
68 if (m_ready) {
return 0;}
72 throw exception(
"Maximum header size exceeded.",
73 status_code::request_header_fields_too_large);
77 m_buf->append(buf,len);
80 std::string::iterator begin = m_buf->begin();
81 std::string::iterator end;
95 if (end == m_buf->end()) {
98 std::copy(begin,end,m_buf->begin());
99 m_buf->resize(static_cast<std::string::size_type>(end-begin));
105 if (end-begin == 0) {
107 if (m_method.empty() ||
get_header(
"Host") ==
"") {
108 throw exception(
"Incomplete Request",status_code::bad_request);
112 size_t bytes_processed = (
113 len -
static_cast<std::string::size_type
>(m_buf->end()-end)
121 return bytes_processed;
123 if (m_method.empty()) {
124 this->process(begin,end);
136 std::stringstream ret;
138 ret << m_method <<
" " << m_uri <<
" " <<
get_version() <<
"\r\n";
145 if (std::find_if(method.begin(),method.end(),
is_not_token_char) != method.end()) {
146 throw exception(
"Invalid method token.",status_code::bad_request);
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) {
171 throw exception(
"Invalid request line1",status_code::bad_request);
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) {
180 throw exception(
"Invalid request line2",status_code::bad_request);
183 set_uri(std::string(cursor_start,cursor_end));
191 #endif // HTTP_PARSER_REQUEST_IMPL_HPP
void set_uri(const std::string &uri)
Set the HTTP uri. Must be a valid HTTP uri.
static char const header_delimiter[]
Literal value of the HTTP header delimiter.
std::string raw()
Returns the full raw request.
bool is_not_token_char(unsigned char c)
Is the character a non-token.
bool parse_complete(std::istream &s)
DEPRECATED parse a complete header ( MUST be in the istream)
void process_header(std::string::iterator begin, std::string::iterator end)
Process a header line.
bool parse_headers(std::istream &s)
Parse headers from an istream.
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.
Namespace for the WebSocket++ project.
size_t const max_header_size
Maximum size in bytes before rejecting an HTTP header as too big.
void set_method(const std::string &method)
Set the HTTP method. Must be a valid HTTP token.
std::string raw_headers() const
Generate and return the HTTP headers as a string.
void set_version(std::string const &version)
Set HTTP parser Version.
size_t consume(const char *buf, size_t len)
Process bytes in the input buffer.