| 120 | } |
| 121 | |
| 122 | void read_with_limit( |
| 123 | std::istream& in, |
| 124 | std::string& buffer, |
| 125 | int delim = '\n' |
| 126 | ) |
| 127 | { |
| 128 | using namespace std; |
| 129 | const size_t max = 64*1024; |
| 130 | buffer.clear(); |
| 131 | buffer.reserve(300); |
| 132 | |
| 133 | while (in.peek() != delim && in.peek() != '\n' && in.peek() != EOF && buffer.size() < max) |
| 134 | { |
| 135 | buffer += (char)in.get(); |
| 136 | } |
| 137 | |
| 138 | // if we quit the loop because the data is longer than expected or we hit EOF |
| 139 | if (in.peek() == EOF) |
| 140 | throw http_parse_error("HTTP field from client terminated incorrectly", 414); |
| 141 | if (buffer.size() == max) |
| 142 | throw http_parse_error("HTTP field from client is too long", 414); |
| 143 | |
| 144 | in.get(); |
| 145 | // eat any remaining whitespace |
| 146 | if (delim == ' ') |
| 147 | { |
| 148 | while (in.peek() == ' ') |
| 149 | in.get(); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // ---------------------------------------------------------------------------------------- |
no test coverage detected