2020-10-20 00:28:33 +00:00
|
|
|
#include "WebUIRequestHandler.h"
|
|
|
|
#include "IServer.h"
|
|
|
|
|
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
|
|
|
#include <Poco/Net/HTTPServerResponse.h>
|
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
|
|
|
|
|
|
|
#include <IO/HTTPCommon.h>
|
2021-12-21 13:41:53 +00:00
|
|
|
#include <Common/getResource.h>
|
2020-10-20 00:28:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
WebUIRequestHandler::WebUIRequestHandler(IServer & server_, std::string resource_name_)
|
|
|
|
: server(server_), resource_name(std::move(resource_name_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-19 12:51:26 +00:00
|
|
|
void WebUIRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response)
|
2020-10-20 00:28:33 +00:00
|
|
|
{
|
|
|
|
auto keep_alive_timeout = server.config().getUInt("keep_alive_timeout", 10);
|
|
|
|
|
|
|
|
response.setContentType("text/html; charset=UTF-8");
|
|
|
|
|
2021-02-19 12:51:26 +00:00
|
|
|
if (request.getVersion() == HTTPServerRequest::HTTP_1_1)
|
2020-10-20 00:28:33 +00:00
|
|
|
response.setChunkedTransferEncoding(true);
|
|
|
|
|
|
|
|
setResponseDefaultHeaders(response, keep_alive_timeout);
|
|
|
|
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_OK);
|
2021-02-19 12:51:26 +00:00
|
|
|
*response.send() << getResource(resource_name);
|
2020-10-20 00:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|