2012-03-09 03:06:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-08-09 14:33:07 +00:00
|
|
|
#include "IServer.h"
|
|
|
|
|
|
|
|
#include <Poco/Net/HTTPRequestHandler.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/CurrentMetrics.h>
|
2017-08-09 14:33:07 +00:00
|
|
|
#include <Common/HTMLForm.h>
|
2012-03-09 03:06:09 +00:00
|
|
|
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
namespace CurrentMetrics
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const Metric HTTPConnection;
|
2016-10-24 04:06:27 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 19:04:46 +00:00
|
|
|
namespace Poco { class Logger; }
|
|
|
|
|
2012-03-09 03:06:09 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-22 15:03:55 +00:00
|
|
|
class WriteBufferFromHTTPServerResponse;
|
2017-02-09 10:10:13 +00:00
|
|
|
|
2014-04-08 13:43:20 +00:00
|
|
|
|
2012-03-09 15:46:52 +00:00
|
|
|
class HTTPHandler : public Poco::Net::HTTPRequestHandler
|
2012-03-09 03:06:09 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-08-09 11:57:09 +00:00
|
|
|
explicit HTTPHandler(IServer & server_);
|
2017-02-06 08:23:02 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response) override;
|
2012-03-09 03:06:09 +00:00
|
|
|
|
2017-02-06 08:23:02 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
struct Output
|
|
|
|
{
|
|
|
|
/* Raw data
|
|
|
|
* ↓
|
|
|
|
* CascadeWriteBuffer out_maybe_delayed_and_compressed (optional)
|
|
|
|
* ↓ (forwards data if an overflow is occur or explicitly via pushDelayedResults)
|
|
|
|
* CompressedWriteBuffer out_maybe_compressed (optional)
|
|
|
|
* ↓
|
|
|
|
* WriteBufferFromHTTPServerResponse out
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::shared_ptr<WriteBufferFromHTTPServerResponse> out;
|
|
|
|
/// Points to 'out' or to CompressedWriteBuffer(*out), depending on settings.
|
|
|
|
std::shared_ptr<WriteBuffer> out_maybe_compressed;
|
|
|
|
/// Points to 'out' or to CompressedWriteBuffer(*out) or to CascadeWriteBuffer.
|
|
|
|
std::shared_ptr<WriteBuffer> out_maybe_delayed_and_compressed;
|
|
|
|
|
|
|
|
inline bool hasDelayed() const
|
|
|
|
{
|
|
|
|
return out_maybe_delayed_and_compressed != out_maybe_compressed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-08-09 11:57:09 +00:00
|
|
|
IServer & server;
|
2017-09-01 19:04:46 +00:00
|
|
|
Poco::Logger * log;
|
2018-03-08 07:36:58 +00:00
|
|
|
|
2018-05-07 02:01:11 +00:00
|
|
|
/// It is the name of the server that will be sent in an http-header X-ClickHouse-Server-Display-Name.
|
2018-03-08 07:36:58 +00:00
|
|
|
String server_display_name;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
CurrentMetrics::Increment metric_increment{CurrentMetrics::HTTPConnection};
|
|
|
|
|
|
|
|
/// Also initializes 'used_output'.
|
|
|
|
void processQuery(
|
|
|
|
Poco::Net::HTTPServerRequest & request,
|
|
|
|
HTMLForm & params,
|
|
|
|
Poco::Net::HTTPServerResponse & response,
|
|
|
|
Output & used_output);
|
|
|
|
|
2017-08-09 14:33:07 +00:00
|
|
|
void trySendExceptionToClient(
|
|
|
|
const std::string & s,
|
|
|
|
int exception_code,
|
|
|
|
Poco::Net::HTTPServerRequest & request,
|
|
|
|
Poco::Net::HTTPServerResponse & response,
|
2017-04-01 07:20:54 +00:00
|
|
|
Output & used_output);
|
|
|
|
|
|
|
|
void pushDelayedResults(Output & used_output);
|
2012-03-09 03:06:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|