13 vector<string> split_tokens(const string &line)
18 for (size_t i = 0; i < line.size(); ++i) {
19 if (isspace(line[i])) {
20 if (!current_token.empty()) {
21 ret.push_back(current_token);
23 current_token.clear();
25 current_token.push_back(line[i]);
28 if (!current_token.empty()) {
29 ret.push_back(current_token);
34 vector<string> split_lines(const string &str)
39 for (size_t i = 0; i < str.size(); ++i) {
40 // Skip \r if followed by an \n.
41 if (str[i] == '\r' && i < str.size() - 1 && str[i + 1] == '\n') {
45 // End of the current line?
47 if (!current_line.empty()) {
48 ret.push_back(current_line);
52 current_line.push_back(str[i]);
55 if (!current_line.empty()) {
56 ret.push_back(current_line);
61 #define MAX_REQUEST_SIZE 16384 /* 16 kB. */
63 RequestParseStatus wait_for_double_newline(string *existing_data, const char *new_data, size_t new_data_size)
65 // Guard against overlong requests gobbling up all of our space.
66 if (existing_data->size() + new_data_size > MAX_REQUEST_SIZE) {
67 return RP_OUT_OF_SPACE;
70 // See if we have \r\n\r\n anywhere in the request. We start three bytes
71 // before what we just appended, in case we just got the final character.
72 size_t existing_data_bytes = existing_data->size();
73 existing_data->append(string(new_data, new_data + new_data_size));
75 const size_t start_at = (existing_data_bytes >= 3 ? existing_data_bytes - 3 : 0);
76 const char *ptr = reinterpret_cast<char *>(
77 memmem(existing_data->data() + start_at, existing_data->size() - start_at,
80 return RP_NOT_FINISHED_YET;
82 if (ptr != existing_data->data() + existing_data->size() - 4) {