ClickHouse/dbms/include/DB/IO/ReadWriteBufferFromHTTP.h

48 lines
1.1 KiB
C++
Raw Normal View History

2016-11-19 00:07:58 +00:00
#pragma once
#include <functional>
2016-11-19 00:07:58 +00:00
#include <Poco/Net/HTTPClientSession.h>
2016-11-24 01:01:11 +00:00
#include <Poco/URI.h>
2016-11-19 00:07:58 +00:00
#include <DB/IO/ReadBufferFromHTTP.h>
#include <DB/IO/ReadBuffer.h>
2017-02-07 06:18:16 +00:00
2016-11-19 00:07:58 +00:00
namespace DB
{
2017-02-07 06:18:16 +00:00
struct HTTPTimeouts
{
2016-11-19 00:07:58 +00:00
Poco::Timespan connection_timeout = Poco::Timespan(DEFAULT_HTTP_READ_BUFFER_CONNECTION_TIMEOUT, 0);
Poco::Timespan send_timeout = Poco::Timespan(DEFAULT_HTTP_READ_BUFFER_TIMEOUT, 0);
Poco::Timespan receive_timeout = Poco::Timespan(DEFAULT_HTTP_READ_BUFFER_TIMEOUT, 0);
};
2017-02-07 06:18:16 +00:00
2016-11-19 00:07:58 +00:00
/** Perform HTTP POST request and provide response to read.
*/
class ReadWriteBufferFromHTTP : public ReadBuffer
{
private:
2016-11-24 01:01:11 +00:00
Poco::URI uri;
std::string method;
2016-11-19 00:07:58 +00:00
HTTPTimeouts timeouts;
Poco::Net::HTTPClientSession session;
std::istream * istr; /// owned by session
std::unique_ptr<ReadBuffer> impl;
public:
2017-02-07 06:18:16 +00:00
using OutStreamCallback = std::function<void(std::ostream &)>;
2016-11-25 00:16:20 +00:00
2016-11-19 00:07:58 +00:00
ReadWriteBufferFromHTTP(
2016-11-24 01:01:11 +00:00
const Poco::URI & uri,
2016-11-24 19:57:24 +00:00
const std::string & method = {},
2016-11-25 00:16:20 +00:00
OutStreamCallback out_stream_callback = {},
2016-11-19 00:07:58 +00:00
size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE,
2017-02-07 06:18:16 +00:00
const HTTPTimeouts & timeouts = {});
2016-11-19 00:07:58 +00:00
bool nextImpl() override;
};
}