2018-12-31 20:04:05 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
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/HttpQuery.h"
|
|
|
|
#include "td/net/HttpReader.h"
|
2018-08-15 14:41:42 +02:00
|
|
|
#include "td/net/SslStream.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/BufferedFd.h"
|
2018-08-16 00:06:53 +02:00
|
|
|
#include "td/utils/ByteFlow.h"
|
2020-07-14 02:37:04 +02:00
|
|
|
#include "td/utils/port/IPAddress.h"
|
2018-08-15 14:41:42 +02:00
|
|
|
#include "td/utils/port/SocketFd.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
namespace detail {
|
2019-06-17 18:12:54 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class HttpConnectionBase : public Actor {
|
|
|
|
public:
|
2020-07-13 10:55:43 +02:00
|
|
|
void write_next_noflush(BufferSlice buffer);
|
2018-12-31 20:04:05 +01:00
|
|
|
void write_next(BufferSlice buffer);
|
|
|
|
void write_ok();
|
|
|
|
void write_error(Status error);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
enum class State { Read, Write, Close };
|
2021-10-27 19:29:01 +02:00
|
|
|
HttpConnectionBase(State state, BufferedFd<SocketFd> fd, SslStream ssl_stream, size_t max_post_size, size_t max_files,
|
2020-07-23 18:47:12 +02:00
|
|
|
int32 idle_timeout, int32 slow_scheduler_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
State state_;
|
2018-08-15 14:41:42 +02:00
|
|
|
|
|
|
|
BufferedFd<SocketFd> fd_;
|
2020-07-13 14:23:03 +02:00
|
|
|
IPAddress peer_address_;
|
2018-08-15 14:41:42 +02:00
|
|
|
SslStream ssl_stream_;
|
|
|
|
|
|
|
|
ByteFlowSource read_source_{&fd_.input_buffer()};
|
|
|
|
ByteFlowSink read_sink_;
|
|
|
|
|
|
|
|
ChainBufferWriter write_buffer_;
|
|
|
|
ChainBufferReader write_buffer_reader_ = write_buffer_.extract_reader();
|
|
|
|
ByteFlowSource write_source_{&write_buffer_reader_};
|
|
|
|
ByteFlowMoveSink write_sink_{&fd_.output_buffer()};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
size_t max_post_size_;
|
|
|
|
size_t max_files_;
|
|
|
|
int32 idle_timeout_;
|
|
|
|
HttpReader reader_;
|
2019-06-17 18:12:54 +02:00
|
|
|
unique_ptr<HttpQuery> current_query_;
|
2018-12-31 20:04:05 +01:00
|
|
|
bool close_after_write_ = false;
|
|
|
|
|
2020-07-23 18:47:12 +02:00
|
|
|
int32 slow_scheduler_id_{-1};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void live_event();
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final;
|
|
|
|
void tear_down() final;
|
|
|
|
void timeout_expired() final;
|
|
|
|
void loop() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void on_start_migrate(int32 sched_id) final;
|
|
|
|
void on_finish_migrate() final;
|
2020-08-10 16:10:16 +02:00
|
|
|
|
2019-06-17 18:12:54 +02:00
|
|
|
virtual void on_query(unique_ptr<HttpQuery> query) = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
virtual void on_error(Status error) = 0;
|
|
|
|
};
|
2019-06-17 18:12:54 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace detail
|
|
|
|
} // namespace td
|