28 #ifndef HTTP_PARSER_RESPONSE_IMPL_HPP 29 #define HTTP_PARSER_RESPONSE_IMPL_HPP 43 if (m_state == DONE) {
return 0;}
45 if (m_state == BODY) {
46 return this->process_body(buf,len);
50 m_buf->append(buf,len);
70 throw exception(
"Maximum header size exceeded.",
74 if (end == m_buf->end()) {
77 std::copy(begin,end,m_buf->begin());
78 m_buf->resize(static_cast<std::string::size_type>(end-begin));
90 if (m_state == RESPONSE_LINE) {
95 std::string length =
get_header(
"Content-Length");
101 std::istringstream ss(length);
103 if ((ss >> m_read).fail()) {
104 throw exception(
"Unable to parse Content-Length header",
113 len -
static_cast<std::string::size_type
>(m_buf->end() - end)
119 read += this->process_body(buf+read,(len-read));
127 if (m_state == RESPONSE_LINE) {
128 this->process(begin,end);
142 size_t bytes_processed;
147 bytes_read =
static_cast<size_t>(s.gcount());
149 if (s.fail() || s.eof()) {
150 bytes_processed = this->
consume(buf,bytes_read);
151 total += bytes_processed;
153 if (bytes_processed != bytes_read) {
157 }
else if (s.bad()) {
164 buf[bytes_read-1] =
'\n';
165 bytes_processed = this->
consume(buf,bytes_read);
166 total += bytes_processed;
168 if (bytes_processed != bytes_read) {
181 std::stringstream ret;
183 ret <<
get_version() <<
" " << m_status_code <<
" " << m_status_msg;
193 m_status_code = code;
201 m_status_code = code;
211 if (cursor_end == end) {
217 cursor_start = cursor_end+1;
218 cursor_end = std::find(cursor_start,end,
' ');
220 if (cursor_end == end) {
226 std::istringstream ss(std::string(cursor_start,cursor_end));
228 if ((ss >> code).fail()) {
235 inline size_t response::process_body(
char const * buf,
size_t len) {
257 m_body.append(buf,to_read);
266 #endif // HTTP_PARSER_RESPONSE_IMPL_HPP
static char const header_delimiter[]
Literal value of the HTTP header delimiter.
void process_header(std::string::iterator begin, std::string::iterator end)
Process a header line.
Table::const_iterator iterator
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.
size_t const istream_buffer
Number of bytes to use for temporary istream read buffers.
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_status(status_code::value code)
Set response status code and message.
std::string raw_headers() const
Generate and return the HTTP headers as a string.
std::string get_string(value code)
Return a human readable interpretation of a WebSocket close code.
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.
std::string raw() const
Returns the full raw response.