comparison Core/HttpServer/MongooseServer.cpp @ 1115:da56a7916e8a

Experimental "KeepAlive" configuration option to enable HTTP Keep-Alive
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 02 Sep 2014 17:30:13 +0200
parents ba5c0908600c
children 1d60316c3618
comparison
equal deleted inserted replaced
1114:adfd2c7a92f3 1115:da56a7916e8a
550 static void InternalCallback(struct mg_connection *connection, 550 static void InternalCallback(struct mg_connection *connection,
551 const struct mg_request_info *request) 551 const struct mg_request_info *request)
552 { 552 {
553 MongooseServer* that = reinterpret_cast<MongooseServer*>(request->user_data); 553 MongooseServer* that = reinterpret_cast<MongooseServer*>(request->user_data);
554 MongooseOutputStream stream(connection); 554 MongooseOutputStream stream(connection);
555 HttpOutput output(stream); 555 HttpOutput output(stream, that->IsKeepAliveEnabled());
556 556
557 // Check remote calls 557 // Check remote calls
558 if (!that->IsRemoteAccessAllowed() && 558 if (!that->IsRemoteAccessAllowed() &&
559 request->remote_ip != LOCALHOST) 559 request->remote_ip != LOCALHOST)
560 { 560 {
784 remoteAllowed_ = false; 784 remoteAllowed_ = false;
785 authentication_ = false; 785 authentication_ = false;
786 ssl_ = false; 786 ssl_ = false;
787 port_ = 8000; 787 port_ = 8000;
788 filter_ = NULL; 788 filter_ = NULL;
789 keepAlive_ = false;
789 790
790 #if ORTHANC_SSL_ENABLED == 1 791 #if ORTHANC_SSL_ENABLED == 1
791 // Check for the Heartbleed exploit 792 // Check for the Heartbleed exploit
792 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug 793 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug
793 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ && 794 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ &&
827 // Set the TCP port for the HTTP server 828 // Set the TCP port for the HTTP server
828 "listening_ports", port.c_str(), 829 "listening_ports", port.c_str(),
829 830
830 // Optimization reported by Chris Hafey 831 // Optimization reported by Chris Hafey
831 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ 832 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ
832 // "enable_keep_alive", "yes", 833 "enable_keep_alive", (keepAlive_ ? "yes" : "no"),
833 834
834 // Set the SSL certificate, if any. This must be the last option. 835 // Set the SSL certificate, if any. This must be the last option.
835 ssl_ ? "ssl_certificate" : NULL, 836 ssl_ ? "ssl_certificate" : NULL,
836 certificate_.c_str(), 837 certificate_.c_str(),
837 NULL 838 NULL
915 #else 916 #else
916 ssl_ = enabled; 917 ssl_ = enabled;
917 #endif 918 #endif
918 } 919 }
919 920
921
922 void MongooseServer::SetKeepAliveEnabled(bool enabled)
923 {
924 Stop();
925 keepAlive_ = enabled;
926 LOG(WARNING) << "HTTP keep alive is " << (enabled ? "enabled" : "disabled");
927 }
928
929
920 void MongooseServer::SetAuthenticationEnabled(bool enabled) 930 void MongooseServer::SetAuthenticationEnabled(bool enabled)
921 { 931 {
922 Stop(); 932 Stop();
923 authentication_ = enabled; 933 authentication_ = enabled;
924 } 934 }