ClickHouse/programs/server/HTTPHandler.h

84 lines
2.3 KiB
C++
Raw Normal View History

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>
#include <Common/CurrentMetrics.h>
2017-08-09 14:33:07 +00:00
#include <Common/HTMLForm.h>
2012-03-09 03:06:09 +00:00
namespace CurrentMetrics
{
extern const Metric HTTPConnection;
}
2017-09-01 19:04:46 +00:00
namespace Poco { class Logger; }
2012-03-09 03:06:09 +00:00
namespace DB
{
class WriteBufferFromHTTPServerResponse;
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_);
void handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response) override;
2012-03-09 03:06:09 +00:00
/// This method is called right before the query execution.
virtual void customizeContext(DB::Context& /* context */) {}
private:
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-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.
String server_display_name;
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,
Output & used_output);
2020-03-18 00:57:00 +00:00
static void pushDelayedResults(Output & used_output);
2012-03-09 03:06:09 +00:00
};
}