tdlight-telegram-bot-api/telegram-bot-api/HttpConnection.h

53 lines
1.5 KiB
C
Raw Normal View History

//
2024-05-30 18:40:54 +02:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "telegram-bot-api/ClientManager.h"
#include "telegram-bot-api/Query.h"
#include "td/net/HttpInboundConnection.h"
#include "td/net/HttpQuery.h"
2022-01-25 16:18:44 +01:00
#include "td/actor/actor.h"
#include "td/utils/buffer.h"
#include "td/utils/Slice.h"
2022-06-30 19:27:08 +02:00
#include "td/utils/Status.h"
#include <memory>
namespace telegram_bot_api {
struct SharedData;
2022-01-25 16:18:44 +01:00
class HttpConnection final : public td::HttpInboundConnection::Callback {
public:
explicit HttpConnection(td::ActorId<ClientManager> client_manager, std::shared_ptr<SharedData> shared_data)
: client_manager_(client_manager), shared_data_(std::move(shared_data)) {
}
2022-01-25 16:18:44 +01:00
void handle(td::unique_ptr<td::HttpQuery> http_query, td::ActorOwn<td::HttpInboundConnection> connection) final;
private:
td::ActorId<ClientManager> client_manager_;
td::ActorOwn<td::HttpInboundConnection> connection_;
std::shared_ptr<SharedData> shared_data_;
2022-01-25 16:18:44 +01:00
void hangup() final {
connection_.release();
stop();
}
void on_query_finished(td::Result<td::unique_ptr<Query>> r_query);
void send_response(int http_status_code, td::BufferSlice &&content, int retry_after);
void send_http_error(int http_status_code, td::Slice description);
};
} // namespace telegram_bot_api