| 94 | } |
| 95 | |
| 96 | void ClientRunningRequest::process_answer_ex_impl(cocoon_api::client_queryAnswerEx &ans) { |
| 97 | if (answer_sent_) { |
| 98 | LOG(ERROR) << "client request " << request_id_.to_hex() << ": received duplicate answer"; |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | LOG(DEBUG) << "client request " << request_id_.to_hex() << ": received answer"; |
| 103 | |
| 104 | auto R = fetch_tl_object<cocoon_api::http_response>(std::move(ans.answer_), true); |
| 105 | if (R.is_error()) { |
| 106 | LOG(ERROR) << "client request " << request_id_.to_hex() << ": received malformed answer: " << R.move_as_error(); |
| 107 | return; |
| 108 | } |
| 109 | auto response = R.move_as_ok(); |
| 110 | |
| 111 | received_answer_at_unix_ = td::Clocks::system(); |
| 112 | |
| 113 | stats()->answer_bytes_sent += (double)response->payload_.size(); |
| 114 | |
| 115 | std::vector<std::pair<std::string, std::string>> headers; |
| 116 | for (auto &x : response->headers_) { |
| 117 | headers.emplace_back(x->name_, x->value_); |
| 118 | } |
| 119 | headers.emplace_back("X-Cocoon-Client-Start", PSTRING() << td::StringBuilder::FixedDouble(started_at_unix_, 6)); |
| 120 | headers.emplace_back("X-Cocoon-Client-End", PSTRING() << td::StringBuilder::FixedDouble(td::Clocks::system(), 6)); |
| 121 | |
| 122 | callback_->receive_answer(response->status_code_, "application/json", std::move(headers)); |
| 123 | answer_sent_ = true; |
| 124 | |
| 125 | bool is_completed = ans.flags_ & 1; |
| 126 | |
| 127 | if (response->payload_.size() > 0) { |
| 128 | payload_parts_++; |
| 129 | payload_bytes_ += response->payload_.size(); |
| 130 | |
| 131 | add_payload_part(std::move(response->payload_), is_completed, ans.final_info_); |
| 132 | } |
| 133 | |
| 134 | if (is_completed) { |
| 135 | finish_request(true, std::move(ans.final_info_)); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void ClientRunningRequest::process_answer_ex_impl(cocoon_api::client_queryAnswerErrorEx &ans) { |
| 140 | LOG(DEBUG) << "client request " << request_id_.to_hex() << ": received error"; |
nothing calls this directly
no test coverage detected