| 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_); |
| 144 | already_started_ = true; |
| 145 | asio::post(strand_, [weak = self_, status_code = (http::status)status_code, |
| 146 | content_type = std::move(content_type), headers = std::move(headers)]() mutable { |
| 147 | if (auto self = weak.lock()) { |
| 148 | self->send_headers(status_code, content_type, std::move(headers)); |
| 149 | } |
| 150 | }); |
| 151 | receive_payload_part(std::move(body_part), is_completed); |
| 152 | } |
| 153 | void receive_payload_part(std::string body_part, bool is_completed) override { |
| 154 | CHECK(already_started_); |
| 155 | CHECK(!already_completed_); |
| 156 | if (body_part.size() > 0) { |
| 157 | asio::post(strand_, [weak = self_, body_part = std::move(body_part)]() mutable { |
| 158 | if (auto self = weak.lock()) { |
| 159 | self->enqueue_part(std::move(body_part)); |
| 160 | } |
| 161 | }); |
| 162 | } |
| 163 | if (is_completed) { |
| 164 | already_completed_ = true; |
| 165 | asio::post(strand_, [weak = self_, body_part = std::move(body_part)]() mutable { |
| 166 | if (auto self = weak.lock()) { |
| 167 | self->finish(); |
| 168 | } |
| 169 | }); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | ~Cb() { |
| 174 | if (!already_started_) { |
| 175 | already_started_ = true; |
| 176 | already_completed_ = true; |
| 177 | asio::post(strand_, [weak = self_]() mutable { |
| 178 | if (auto self = weak.lock()) { |
| 179 | self->send_headers(http::status::internal_server_error, "text/plain", {}); |
| 180 | self->enqueue_part(PSTRING() << "lost http callback"); |
| 181 | self->finish(); |
| 182 | } |
| 183 | }); |
| 184 | } |
| 185 | if (!already_completed_) { |
| 186 | already_completed_ = true; |
| 187 | asio::post(strand_, [weak = self_]() mutable { |
| 188 | if (auto self = weak.lock()) { |
| 189 | self->finish(); |
| 190 | } |
nothing calls this directly
no outgoing calls
no test coverage detected