comparison Core/HttpServer/HttpServer.cpp @ 3537:9cc09f4c0fa9

New configuration option: "HttpRequestTimeout"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Oct 2019 13:16:15 +0200
parents 4944b03bb9c6
children 94f4a18a79cc
comparison
equal deleted inserted replaced
3536:8be5451f6820 3537:9cc09f4c0fa9
1071 httpCompression_ = true; 1071 httpCompression_ = true;
1072 exceptionFormatter_ = NULL; 1072 exceptionFormatter_ = NULL;
1073 realm_ = ORTHANC_REALM; 1073 realm_ = ORTHANC_REALM;
1074 threadsCount_ = 50; // Default value in mongoose 1074 threadsCount_ = 50; // Default value in mongoose
1075 tcpNoDelay_ = true; 1075 tcpNoDelay_ = true;
1076 requestTimeout_ = 30; // Default value in mongoose/civetweb (30 seconds)
1076 1077
1077 #if ORTHANC_ENABLE_MONGOOSE == 1 1078 #if ORTHANC_ENABLE_MONGOOSE == 1
1078 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server"; 1079 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server";
1079 #endif 1080 #endif
1080 1081
1118 1119
1119 if (!IsRunning()) 1120 if (!IsRunning())
1120 { 1121 {
1121 std::string port = boost::lexical_cast<std::string>(port_); 1122 std::string port = boost::lexical_cast<std::string>(port_);
1122 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_); 1123 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_);
1124 std::string requestTimeoutMilliseconds = boost::lexical_cast<std::string>(requestTimeout_ * 1000);
1123 1125
1124 if (ssl_) 1126 if (ssl_)
1125 { 1127 {
1126 port += "s"; 1128 port += "s";
1127 } 1129 }
1148 #endif 1150 #endif
1149 1151
1150 // Set the number of threads 1152 // Set the number of threads
1151 "num_threads", numThreads.c_str(), 1153 "num_threads", numThreads.c_str(),
1152 1154
1155 // Set the timeout for the HTTP server
1156 "request_timeout_ms", requestTimeoutMilliseconds.c_str(),
1157
1153 // Set the SSL certificate, if any. This must be the last option. 1158 // Set the SSL certificate, if any. This must be the last option.
1154 ssl_ ? "ssl_certificate" : NULL, 1159 ssl_ ? "ssl_certificate" : NULL,
1155 certificate_.c_str(), 1160 certificate_.c_str(),
1156 NULL 1161 NULL
1157 }; 1162 };
1320 threadsCount_ = threads; 1325 threadsCount_ = threads;
1321 1326
1322 LOG(INFO) << "The embedded HTTP server will use " << threads << " threads"; 1327 LOG(INFO) << "The embedded HTTP server will use " << threads << " threads";
1323 } 1328 }
1324 1329
1325 1330
1326 void HttpServer::SetTcpNoDelay(bool tcpNoDelay) 1331 void HttpServer::SetTcpNoDelay(bool tcpNoDelay)
1327 { 1332 {
1328 Stop(); 1333 Stop();
1329 tcpNoDelay_ = tcpNoDelay; 1334 tcpNoDelay_ = tcpNoDelay;
1330 LOG(INFO) << "TCP_NODELAY for the HTTP sockets is set to " 1335 LOG(INFO) << "TCP_NODELAY for the HTTP sockets is set to "
1331 << (tcpNoDelay ? "true" : "false"); 1336 << (tcpNoDelay ? "true" : "false");
1332 } 1337 }
1338
1339
1340 void HttpServer::SetRequestTimeout(unsigned int seconds)
1341 {
1342 if (seconds <= 0)
1343 {
1344 throw OrthancException(ErrorCode_ParameterOutOfRange,
1345 "Request timeout must be a stricly positive integer");
1346 }
1347
1348 Stop();
1349 requestTimeout_ = seconds;
1350 LOG(INFO) << "Request timeout in the HTTP server is set to " << seconds << " seconds";
1351 }
1333 } 1352 }