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);
53 std::string::iterator begin = m_buf->begin();
54 std::string::iterator end = begin;
63 header_delimiter +
sizeof(header_delimiter) - 1
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)
114 +
sizeof(header_delimiter) - 1
119 read += this->process_body(
buf+read,(
len-read));
127 if (m_state == RESPONSE_LINE) {
128 this->process(begin,end);
135 begin = end+(
sizeof(header_delimiter) - 1);
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;
194 m_status_msg = get_string(code);
201 m_status_code = code;
205inline void response::process(std::string::iterator begin,
206 std::string::iterator end)
208 std::string::iterator cursor_start = begin;
209 std::string::iterator cursor_end = std::find(begin,end,
' ');
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()) {
235inline size_t response::process_body(
char const *
buf,
size_t len) {
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.
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.
void set_status(status_code::value code)
Set response status code and message.
std::string raw() const
Returns the full raw response.
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
@ request_header_fields_too_large
size_t const istream_buffer
Number of bytes to use for temporary istream read buffers.
size_t const max_header_size
Maximum size in bytes before rejecting an HTTP header as too big.
Namespace for the WebSocket++ project.