| 84 | } |
| 85 | |
| 86 | void handle_request() { |
| 87 | HttpCallback::RequestType request_type = HttpCallback::RequestType::Get; |
| 88 | switch (req_.method()) { |
| 89 | case http::verb::get: |
| 90 | request_type = HttpCallback::RequestType::Get; |
| 91 | break; |
| 92 | case http::verb::post: |
| 93 | request_type = HttpCallback::RequestType::Post; |
| 94 | break; |
| 95 | default: |
| 96 | UNREACHABLE(); |
| 97 | } |
| 98 | |
| 99 | std::vector<std::pair<std::string, std::string>> headers; |
| 100 | for (auto &h : req_) { |
| 101 | auto name = h.name_string(); |
| 102 | if (allow_header(name)) { |
| 103 | auto value = h.value(); |
| 104 | headers.emplace_back(name, value); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | auto url = req_.target(); |
| 109 | for (const auto &s : {"http://", "https://"}) { |
| 110 | if (url.starts_with(s)) { |
| 111 | url.remove_prefix(strlen(s)); |
| 112 | auto p = url.find('/'); |
| 113 | if (p != url.npos) { |
| 114 | url.remove_prefix(p); |
| 115 | } else { |
| 116 | url = "/"; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | std::string_view args; |
| 122 | auto p = url.find('?'); |
| 123 | if (p != url.npos) { |
| 124 | args = url.substr(p + 1); |
| 125 | url = url.substr(0, p); |
| 126 | } |
| 127 | |
| 128 | std::vector<std::pair<std::string, std::string>> args_vec; |
| 129 | if (args.size() > 0) { |
| 130 | args_vec = parse_x_www_form_urlencoded(td::Slice(args.begin(), args.end())); |
| 131 | } |
| 132 | |
| 133 | class Cb : public HttpRequestCallback { |
| 134 | public: |
| 135 | Cb(std::weak_ptr<HttpSession> self, asio::strand<asio::any_io_executor> strand) |
| 136 | : self_(std::move(self)), strand_(std::move(strand)) { |
| 137 | } |
| 138 | |
| 139 | void receive_answer(td::int32 status_code, std::string content_type, |
| 140 | std::vector<std::pair<std::string, std::string>> headers, std::string body_part = "", |
| 141 | bool is_completed = false) override { |
| 142 | CHECK(!already_started_); |
| 143 | CHECK(!already_completed_); |
nothing calls this directly
no test coverage detected