MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / run

Method run

src/Server/HTTP/HTTPServerConnection.cpp:38–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38void HTTPServerConnection::run()
39{
40 DB::setThreadName(ThreadName::HTTP_SERVER_CONN);
41
42 std::string server = params->getSoftwareVersion();
43 Poco::Net::HTTPServerSession session(socket(), params);
44
45 ProfileEvents::increment(ProfileEvents::HTTPServerConnectionsCreated);
46
47 while (!stopped && tcp_server.isOpen() && session.connected())
48 {
49 const bool is_first_request = params->getMaxKeepAliveRequests() == session.getMaxKeepAliveRequests();
50
51 if (!session.hasMoreRequests())
52 {
53 if (is_first_request)
54 // it is strange to have a connection being opened but no request has been sent, account it as an error case
55 ProfileEvents::increment(ProfileEvents::HTTPServerConnectionsReset);
56 else
57 ProfileEvents::increment(ProfileEvents::HTTPServerConnectionsExpired);
58
59 return;
60 }
61 else
62 {
63 if (!is_first_request)
64 ProfileEvents::increment(ProfileEvents::HTTPServerConnectionsReused);
65 }
66
67 try
68 {
69 std::lock_guard lock(mutex);
70 if (!stopped && tcp_server.isOpen() && session.connected())
71 {
72 HTTPServerResponse response(session);
73 HTTPServerRequest request(context, response, session, read_event);
74
75 Poco::Timestamp now;
76
77 if (!forwarded_for.empty())
78 request.set("X-Forwarded-For", forwarded_for);
79
80 if (request.isSecure())
81 {
82 size_t hsts_max_age = context->getMaxHstsAge();
83
84 if (hsts_max_age > 0)
85 response.add("Strict-Transport-Security", "max-age=" + std::to_string(hsts_max_age));
86
87 }
88
89 response.setDate(now);
90 response.setVersion(request.getVersion());
91 response.setKeepAlive(params->getKeepAlive() && request.getKeepAlive() && session.canKeepAlive());
92 if (!server.empty())
93 response.set("Server", server);
94 try
95 {

Callers

nothing calls this directly

Calls 15

hasMoreRequestsMethod · 0.80
setDateMethod · 0.80
getExpectContinueMethod · 0.80
displayTextMethod · 0.80
networkExceptionMethod · 0.80
setThreadNameFunction · 0.50
incrementFunction · 0.50
to_stringFunction · 0.50
getLoggerFunction · 0.50
isOpenMethod · 0.45

Tested by

no test coverage detected