return false if any error
| 42 | |
| 43 | // return false if any error |
| 44 | bool CHttpContext::ParseRequest(base::CBuffer* buf, uint64_t receive_time) { |
| 45 | bool ok = true; |
| 46 | bool hasMore = true; |
| 47 | while (hasMore) { |
| 48 | if (_state == ExpectRequestLine) { |
| 49 | char line_buf[1024] = {0}; |
| 50 | int need_len = 0; |
| 51 | int size = buf->ReadUntil(line_buf, 1024, CRLF, CRLF_LEN, need_len); |
| 52 | if (size > 0) { |
| 53 | ok = processRequestLine(line_buf, line_buf + size); |
| 54 | if (ok) { |
| 55 | _request.SetReceiveTime(receive_time); |
| 56 | _state = ExpectHeaders; |
| 57 | |
| 58 | } else { |
| 59 | hasMore = false; |
| 60 | } |
| 61 | |
| 62 | } else { |
| 63 | hasMore = false; |
| 64 | } |
| 65 | |
| 66 | } else if (_state == ExpectHeaders) { |
| 67 | char line_buf[1024] = { 0 }; |
| 68 | int need_len = 0; |
| 69 | int size = buf->ReadUntil(line_buf, 1024, CRLF, CRLF_LEN, need_len); |
| 70 | char* end = line_buf + size - CRLF_LEN; |
| 71 | if (size > 0) { |
| 72 | const char* colon = std::find(line_buf, end, ':'); |
| 73 | if (colon != end) { |
| 74 | _request.AddHeader(line_buf, colon, end); |
| 75 | |
| 76 | } else { |
| 77 | // empty line, end of header |
| 78 | // FIXME: |
| 79 | _state = GotAll; |
| 80 | hasMore = false; |
| 81 | } |
| 82 | |
| 83 | } else { |
| 84 | hasMore = false; |
| 85 | } |
| 86 | |
| 87 | } else if (_state == ExpectBody) { |
| 88 | // TODO: |
| 89 | } |
| 90 | } |
| 91 | return ok; |
| 92 | } |
no test coverage detected