28 #ifndef HTTP_PARSER_IMPL_HPP
29 #define HTTP_PARSER_IMPL_HPP
39 inline void parser::set_version(std::string
const & version) {
43 inline std::string
const & parser::get_header(std::string
const & key)
const {
44 header_list::const_iterator h = m_headers.find(key);
46 if (h == m_headers.end()) {
53 inline bool parser::get_header_as_plist(std::string
const & key,
56 header_list::const_iterator it = m_headers.find(key);
58 if (it == m_headers.end() || it->second.size() == 0) {
65 inline void parser::append_header(std::string
const & key, std::string
const &
69 throw exception(
"Invalid header name",status_code::bad_request);
75 m_headers[key] +=
", " + val;
79 inline void parser::replace_header(std::string
const & key, std::string
const &
85 inline void parser::remove_header(std::string
const & key) {
89 inline void parser::set_body(std::string
const &
value) {
90 if (value.size() == 0) {
96 std::stringstream len;
102 inline bool parser::parse_parameter_list(std::string
const & in,
105 if (in.size() == 0) {
109 std::string::const_iterator it;
110 it = extract_parameters(in.begin(),in.end(),out);
111 return (it == in.begin());
114 inline bool parser::parse_headers(std::istream & s) {
116 std::string::size_type end;
119 while (std::getline(s, header) && header !=
"\r") {
120 if (header[header.size()-1] !=
'\r') {
123 header.erase(header.end()-1);
128 if (end != std::string::npos) {
136 inline void parser::process_header(std::string::iterator begin,
137 std::string::iterator end)
139 std::string::iterator cursor = std::search(
147 throw exception(
"Invalid header line",status_code::bad_request);
154 inline std::string parser::raw_headers()
const {
155 std::stringstream raw;
157 header_list::const_iterator it;
158 for (it = m_headers.begin(); it != m_headers.end(); it++) {
159 raw << it->first <<
": " << it->second <<
"\r\n";
171 #endif // HTTP_PARSER_IMPL_HPP
uint16_t value
The type of a close code value.
static std::string const empty_header
Literal value of an empty header.
bool parse_parameter_list(std::string const &in, parameter_list &out) const
Extract an HTTP parameter list from a string.
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list.
bool is_not_token_char(unsigned char c)
Is the character a non-token.
std::string const & get_header(std::string const &key) const
Get the value of an HTTP header.
static char const header_separator[]
Literal value of the HTTP header separator.
Namespace for the WebSocket++ project.
void append_header(std::string const &key, std::string const &val)
Append a value to an existing HTTP header.
void replace_header(std::string const &key, std::string const &val)
Set a value for an HTTP header, replacing an existing value.
void remove_header(std::string const &key)
Remove a header from the parser.