2014-03-21 17:23:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-05-28 12:22:22 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
#include <Poco/Net/HTTPClientSession.h>
|
|
|
|
|
|
|
|
#include <DB/IO/ReadBuffer.h>
|
2016-08-19 01:54:23 +00:00
|
|
|
#include <DB/Core/Types.h>
|
2014-03-21 17:23:09 +00:00
|
|
|
|
|
|
|
#define DEFAULT_HTTP_READ_BUFFER_TIMEOUT 1800
|
2014-12-18 11:39:55 +00:00
|
|
|
#define DEFAULT_HTTP_READ_BUFFER_CONNECTION_TIMEOUT 1
|
2014-03-21 17:23:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-08-19 01:54:23 +00:00
|
|
|
/** Perform HTTP-request and provide response to read.
|
2014-03-21 17:23:09 +00:00
|
|
|
*/
|
|
|
|
class ReadBufferFromHTTP : public ReadBuffer
|
|
|
|
{
|
|
|
|
private:
|
2016-08-19 01:54:23 +00:00
|
|
|
String host;
|
2014-03-21 17:23:09 +00:00
|
|
|
int port;
|
2016-11-15 23:55:45 +00:00
|
|
|
String path;
|
2016-11-16 00:34:57 +00:00
|
|
|
String method;
|
2014-03-21 17:23:09 +00:00
|
|
|
|
|
|
|
Poco::Net::HTTPClientSession session;
|
2016-08-19 01:54:23 +00:00
|
|
|
std::istream * istr; /// owned by session
|
|
|
|
std::unique_ptr<ReadBuffer> impl;
|
2014-03-21 17:23:09 +00:00
|
|
|
|
|
|
|
public:
|
2016-08-19 01:54:23 +00:00
|
|
|
using Params = std::vector<std::pair<String, String>>;
|
2014-04-02 13:45:39 +00:00
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
ReadBufferFromHTTP(
|
2016-08-19 01:54:23 +00:00
|
|
|
const String & host_,
|
2014-03-21 17:23:09 +00:00
|
|
|
int port_,
|
2016-11-15 23:55:45 +00:00
|
|
|
const String & path_,
|
2014-04-02 13:45:39 +00:00
|
|
|
const Params & params,
|
2016-11-15 23:55:45 +00:00
|
|
|
const String & method_ = "",
|
2014-12-18 11:39:55 +00:00
|
|
|
size_t buffer_size_ = DBMS_DEFAULT_BUFFER_SIZE,
|
|
|
|
const Poco::Timespan & connection_timeout = Poco::Timespan(DEFAULT_HTTP_READ_BUFFER_CONNECTION_TIMEOUT, 0),
|
|
|
|
const Poco::Timespan & send_timeout = Poco::Timespan(DEFAULT_HTTP_READ_BUFFER_TIMEOUT, 0),
|
2016-08-19 01:54:23 +00:00
|
|
|
const Poco::Timespan & receive_timeout = Poco::Timespan(DEFAULT_HTTP_READ_BUFFER_TIMEOUT, 0));
|
2014-03-21 17:23:09 +00:00
|
|
|
|
2016-08-19 01:54:23 +00:00
|
|
|
bool nextImpl() override;
|
2014-03-21 17:23:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|