18 #include <hicn/transport/core/packet.h>
20 #include "http_1x_message_fast_parser.h"
22 #define ASIO_STANDALONE
33 typedef std::function<void(
const uint8_t *data, std::size_t size,
bool is_last,
34 bool headers, Metadata *metadata)>
35 ContentReceivedCallback;
36 typedef std::function<bool(asio::ip::tcp::socket &socket)> OnConnectionClosed;
37 typedef std::function<void()> ContentSentCallback;
39 std::pair<std::unique_ptr<utils::MemBuf>, ContentSentCallback>>
43 std::string http_version;
53 std::string status_code;
54 std::string status_string;
57 class HTTPClientConnectionCallback;
60 friend class HTTPClientConnectionCallback;
61 static constexpr uint32_t buffer_size = 1024 * 512;
63 enum class ConnectorState {
70 HTTPSession(asio::io_service &io_service, std::string &ip_address,
71 std::string &port, ContentReceivedCallback receive_callback,
72 OnConnectionClosed on_reconnect_callback,
bool client =
false);
75 ContentReceivedCallback receive_callback,
76 OnConnectionClosed on_reconnect_callback,
bool client =
true);
80 void send(
const uint8_t *buffer, std::size_t len,
81 ContentSentCallback &&content_sent = 0);
83 void send(
utils::MemBuf *buffer, ContentSentCallback &&content_sent);
92 void doReadBody(std::size_t body_size, std::size_t additional_bytes);
94 void doReadChunkedHeader();
98 bool checkConnected();
101 void handleRead(std::error_code ec, std::size_t length);
102 void tryReconnection();
103 void startConnectionTimer();
104 void handleDeadline(
const std::error_code &ec);
106 asio::io_service &io_service_;
107 asio::ip::tcp::socket socket_;
108 asio::ip::tcp::resolver resolver_;
109 asio::ip::tcp::resolver::iterator endpoint_iterator_;
110 asio::steady_timer timer_;
112 BufferQueue write_msgs_;
114 asio::streambuf input_buffer_;
117 bool is_reconnection_;
118 bool data_available_;
120 std::size_t content_length_;
126 ContentReceivedCallback receive_callback_;
127 OnConnectionClosed on_connection_closed_callback_;
130 std::unique_ptr<Metadata> header_info_;
133 ConnectorState state_;