1 | #include "HTTPHandlerFactory.h" |
---|---|
2 | |
3 | |
4 | namespace DB |
5 | { |
6 | |
7 | HTTPRequestHandlerFactoryMain::HTTPRequestHandlerFactoryMain(IServer & server_, const std::string & name_) |
8 | : server(server_), log(&Logger::get(name_)), name(name_) |
9 | { |
10 | } |
11 | |
12 | Poco::Net::HTTPRequestHandler * HTTPRequestHandlerFactoryMain::createRequestHandler( |
13 | const Poco::Net::HTTPServerRequest & request) // override |
14 | { |
15 | LOG_TRACE(log, "HTTP Request for "<< name << ". " |
16 | << "Method: " |
17 | << request.getMethod() |
18 | << ", Address: " |
19 | << request.clientAddress().toString() |
20 | << ", User-Agent: " |
21 | << (request.has("User-Agent") ? request.get( "User-Agent") : "none") |
22 | << (request.hasContentLength() ? (", Length: "+ std::to_string(request.getContentLength())) : ( "")) |
23 | << ", Content Type: "<< request.getContentType() |
24 | << ", Transfer Encoding: "<< request.getTransferEncoding()); |
25 | |
26 | for (auto & handlerFactory: child_handler_factories) |
27 | { |
28 | auto handler = handlerFactory->createRequestHandler(request); |
29 | if (handler != nullptr) |
30 | return handler; |
31 | } |
32 | |
33 | if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET |
34 | || request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD |
35 | || request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST) |
36 | { |
37 | return new NotFoundHandler; |
38 | } |
39 | |
40 | return nullptr; |
41 | } |
42 | |
43 | } |
44 |