10 vector<string> split_tokens(const string &line)
15 for (size_t i = 0; i < line.size(); ++i) {
16 if (isspace(line[i])) {
17 if (!current_token.empty()) {
18 ret.push_back(current_token);
20 current_token.clear();
22 current_token.push_back(line[i]);
25 if (!current_token.empty()) {
26 ret.push_back(current_token);
31 vector<string> split_lines(const string &str)
36 for (size_t i = 0; i < str.size(); ++i) {
37 // Skip \r if followed by an \n.
38 if (str[i] == '\r' && i < str.size() - 1 && str[i + 1] == '\n') {
42 // End of the current line?
44 if (!current_line.empty()) {
45 ret.push_back(current_line);
49 current_line.push_back(str[i]);
52 if (!current_line.empty()) {
53 ret.push_back(current_line);
58 #define MAX_REQUEST_SIZE 16384 /* 16 kB. */
60 RequestParseStatus wait_for_double_newline(string *existing_data, const char *new_data, size_t new_data_size)
62 // Guard against overlong requests gobbling up all of our space.
63 if (existing_data->size() + new_data_size > MAX_REQUEST_SIZE) {
64 return RP_OUT_OF_SPACE;
67 // See if we have \r\n\r\n anywhere in the request. We start three bytes
68 // before what we just appended, in case we just got the final character.
69 size_t existing_data_bytes = existing_data->size();
70 existing_data->append(string(new_data, new_data + new_data_size));
72 const size_t start_at = (existing_data_bytes >= 3 ? existing_data_bytes - 3 : 0);
73 const char *ptr = reinterpret_cast<char *>(
74 memmem(existing_data->data() + start_at, existing_data->size() - start_at,
77 return RP_NOT_FINISHED_YET;
79 if (ptr != existing_data->data() + existing_data->size() - 4) {