comparison OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 5119:bdec57f3cbf2

New configuration KeepAliveTimeout with a default value of 1 second
author Alain Mazy <am@osimis.io>
date Wed, 14 Dec 2022 11:50:43 +0100
parents d842e4446e63
children 0ea402b4d901
comparison
equal deleted inserted replaced
5118:030cd210845e 5119:bdec57f3cbf2
351 void HandleInternal(const MultipartStreamReader::HttpHeaders& headers, 351 void HandleInternal(const MultipartStreamReader::HttpHeaders& headers,
352 const void* part, 352 const void* part,
353 size_t size) 353 size_t size)
354 { 354 {
355 StringHttpOutput stringOutput; 355 StringHttpOutput stringOutput;
356 HttpOutput fakeOutput(stringOutput, false); 356 HttpOutput fakeOutput(stringOutput, false /* assume no keep-alive */, 0);
357 HttpToolbox::GetArguments getArguments; 357 HttpToolbox::GetArguments getArguments;
358 358
359 if (!handler_.Handle(fakeOutput, RequestOrigin_RestApi, remoteIp_.c_str(), username_.c_str(), 359 if (!handler_.Handle(fakeOutput, RequestOrigin_RestApi, remoteIp_.c_str(), username_.c_str(),
360 HttpMethod_Post, uri_, headers, getArguments, part, size)) 360 HttpMethod_Post, uri_, headers, getArguments, part, size))
361 { 361 {
1454 HttpServer* server = reinterpret_cast<HttpServer*>(that); 1454 HttpServer* server = reinterpret_cast<HttpServer*>(that);
1455 1455
1456 if (server == NULL) 1456 if (server == NULL)
1457 { 1457 {
1458 MongooseOutputStream stream(connection); 1458 MongooseOutputStream stream(connection);
1459 HttpOutput output(stream, false /* assume no keep-alive */); 1459 HttpOutput output(stream, false /* assume no keep-alive */, 0);
1460 output.SendStatus(HttpStatus_500_InternalServerError); 1460 output.SendStatus(HttpStatus_500_InternalServerError);
1461 return; 1461 return;
1462 } 1462 }
1463 1463
1464 MongooseOutputStream stream(connection); 1464 MongooseOutputStream stream(connection);
1465 HttpOutput output(stream, server->IsKeepAliveEnabled()); 1465 HttpOutput output(stream, server->IsKeepAliveEnabled(), server->GetKeepAliveTimeout());
1466 HttpMethod method = HttpMethod_Get; 1466 HttpMethod method = HttpMethod_Get;
1467 1467
1468 try 1468 try
1469 { 1469 {
1470 try 1470 try
1586 sslMinimumVersion_(0), // Default to any of "SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2" 1586 sslMinimumVersion_(0), // Default to any of "SSL2+SSL3+TLS1.0+TLS1.1+TLS1.2"
1587 sslHasCiphers_(false), 1587 sslHasCiphers_(false),
1588 port_(8000), 1588 port_(8000),
1589 filter_(NULL), 1589 filter_(NULL),
1590 keepAlive_(false), 1590 keepAlive_(false),
1591 keepAliveTimeout_(1),
1591 httpCompression_(true), 1592 httpCompression_(true),
1592 exceptionFormatter_(NULL), 1593 exceptionFormatter_(NULL),
1593 realm_(ORTHANC_REALM), 1594 realm_(ORTHANC_REALM),
1594 threadsCount_(50), // Default value in mongoose/civetweb 1595 threadsCount_(50), // Default value in mongoose/civetweb
1595 tcpNoDelay_(true), 1596 tcpNoDelay_(true),
1653 if (!IsRunning()) 1654 if (!IsRunning())
1654 { 1655 {
1655 std::string port = boost::lexical_cast<std::string>(port_); 1656 std::string port = boost::lexical_cast<std::string>(port_);
1656 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_); 1657 std::string numThreads = boost::lexical_cast<std::string>(threadsCount_);
1657 std::string requestTimeoutMilliseconds = boost::lexical_cast<std::string>(requestTimeout_ * 1000); 1658 std::string requestTimeoutMilliseconds = boost::lexical_cast<std::string>(requestTimeout_ * 1000);
1658 std::string keepAliveTimeoutMilliseconds = boost::lexical_cast<std::string>(CIVETWEB_KEEP_ALIVE_TIMEOUT_SECONDS * 1000); 1659 std::string keepAliveTimeoutMilliseconds = boost::lexical_cast<std::string>(keepAliveTimeout_ * 1000);
1659 std::string sslMinimumVersion = boost::lexical_cast<std::string>(sslMinimumVersion_); 1660 std::string sslMinimumVersion = boost::lexical_cast<std::string>(sslMinimumVersion_);
1660 1661
1661 if (ssl_) 1662 if (ssl_)
1662 { 1663 {
1663 port += "s"; 1664 port += "s";
1957 CLOG(WARNING, HTTP) << "You should disable HTTP keep alive, as you are using Mongoose"; 1958 CLOG(WARNING, HTTP) << "You should disable HTTP keep alive, as you are using Mongoose";
1958 } 1959 }
1959 #endif 1960 #endif
1960 } 1961 }
1961 1962
1963 void HttpServer::SetKeepAliveTimeout(unsigned int timeout)
1964 {
1965 Stop();
1966 keepAliveTimeout_ = timeout;
1967 CLOG(INFO, HTTP) << "HTTP keep alive Timeout is now " << keepAliveTimeout_ << " seconds";
1968
1969 #if ORTHANC_ENABLE_MONGOOSE == 1
1970 if (enabled)
1971 {
1972 CLOG(WARNING, HTTP) << "You should disable HTTP keep alive, as you are using Mongoose";
1973 }
1974 #endif
1975 }
1976
1962 const std::string &HttpServer::GetSslCertificate() const 1977 const std::string &HttpServer::GetSslCertificate() const
1963 { 1978 {
1964 return certificate_; 1979 return certificate_;
1965 } 1980 }
1966 1981
1994 } 2009 }
1995 2010
1996 bool HttpServer::IsKeepAliveEnabled() const 2011 bool HttpServer::IsKeepAliveEnabled() const
1997 { 2012 {
1998 return keepAlive_; 2013 return keepAlive_;
2014 }
2015
2016 unsigned int HttpServer::GetKeepAliveTimeout() const
2017 {
2018 return keepAliveTimeout_;
1999 } 2019 }
2000 2020
2001 void HttpServer::SetRemoteAccessAllowed(bool allowed) 2021 void HttpServer::SetRemoteAccessAllowed(bool allowed)
2002 { 2022 {
2003 Stop(); 2023 Stop();