2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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 "td/net/HttpOutboundConnection.h"
|
|
|
|
#include "td/net/HttpQuery.h"
|
2022-11-11 12:23:43 +01:00
|
|
|
#include "td/net/SslCtx.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/actor.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class Wget final : public HttpOutboundConnection::Callback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2019-06-17 18:12:54 +02:00
|
|
|
explicit Wget(Promise<unique_ptr<HttpQuery>> promise, string url, std::vector<std::pair<string, string>> headers = {},
|
2018-07-01 03:45:25 +02:00
|
|
|
int32 timeout_in = 10, int32 ttl = 3, bool prefer_ipv6 = false,
|
2022-11-11 12:23:43 +01:00
|
|
|
SslCtx::VerifyPeer verify_peer = SslCtx::VerifyPeer::On, string content = {}, string content_type = {});
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Status try_init();
|
2021-07-03 22:51:36 +02:00
|
|
|
void loop() final;
|
|
|
|
void handle(unique_ptr<HttpQuery> result) final;
|
|
|
|
void on_connection_error(Status error) final;
|
2019-06-17 18:12:54 +02:00
|
|
|
void on_ok(unique_ptr<HttpQuery> http_query_ptr);
|
2018-12-31 20:04:05 +01:00
|
|
|
void on_error(Status error);
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void tear_down() final;
|
|
|
|
void start_up() final;
|
|
|
|
void timeout_expired() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-06-17 18:12:54 +02:00
|
|
|
Promise<unique_ptr<HttpQuery>> promise_;
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorOwn<HttpOutboundConnection> connection_;
|
|
|
|
string input_url_;
|
|
|
|
std::vector<std::pair<string, string>> headers_;
|
|
|
|
int32 timeout_in_;
|
|
|
|
int32 ttl_;
|
2018-07-01 03:45:25 +02:00
|
|
|
bool prefer_ipv6_ = false;
|
2022-11-11 12:23:43 +01:00
|
|
|
SslCtx::VerifyPeer verify_peer_;
|
2019-11-19 13:11:19 +01:00
|
|
|
string content_;
|
|
|
|
string content_type_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|