2012-03-09 03:06:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-08-04 19:48:50 +00:00
|
|
|
#include <DB/IO/WriteBufferFromHTTPServerResponse.h>
|
2016-01-21 01:47:28 +00:00
|
|
|
#include <DB/Common/CurrentMetrics.h>
|
2012-03-09 03:06:09 +00:00
|
|
|
#include "Server.h"
|
|
|
|
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
namespace CurrentMetrics
|
|
|
|
{
|
|
|
|
extern const Metric HTTPConnection;
|
|
|
|
}
|
|
|
|
|
2012-03-09 03:06:09 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
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:
|
2012-03-09 15:46:52 +00:00
|
|
|
HTTPHandler(Server & server_)
|
2012-03-09 03:06:09 +00:00
|
|
|
: server(server_)
|
2012-03-09 15:46:52 +00:00
|
|
|
, log(&Logger::get("HTTPHandler"))
|
2012-03-09 03:06:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-04 19:48:50 +00:00
|
|
|
struct Output
|
|
|
|
{
|
2016-05-28 14:14:18 +00:00
|
|
|
std::shared_ptr<WriteBufferFromHTTPServerResponse> out;
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Used for sending response. Points to 'out', or to CompressedWriteBuffer(*out), depending on settings.
|
2016-05-28 14:14:18 +00:00
|
|
|
std::shared_ptr<WriteBuffer> out_maybe_compressed;
|
2014-08-04 19:48:50 +00:00
|
|
|
};
|
|
|
|
|
2016-10-10 08:44:52 +00:00
|
|
|
void handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response) override;
|
2014-08-04 19:48:50 +00:00
|
|
|
|
2015-06-29 21:35:35 +00:00
|
|
|
void trySendExceptionToClient(const std::string & s,
|
2014-08-04 19:48:50 +00:00
|
|
|
Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response,
|
|
|
|
Output & used_output);
|
2012-03-09 03:06:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Server & server;
|
|
|
|
|
2016-01-21 01:47:28 +00:00
|
|
|
CurrentMetrics::Increment metric_increment{CurrentMetrics::HTTPConnection};
|
|
|
|
|
2012-03-09 03:06:09 +00:00
|
|
|
Logger * log;
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Also initializes 'used_output'.
|
2016-06-25 07:22:12 +00:00
|
|
|
void processQuery(
|
|
|
|
Poco::Net::HTTPServerRequest & request,
|
|
|
|
HTMLForm & params,
|
|
|
|
Poco::Net::HTTPServerResponse & response,
|
|
|
|
Output & used_output);
|
2012-03-09 03:06:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|