Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 4193:ff24a06b3474
fix HttpServer options if sslVerifyPeers_ == false and ssl_ == true
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 15 Sep 2020 19:34:22 +0200 |
parents | 9ce5c89328f5 |
children | 2d5209153b32 |
comparison
equal
deleted
inserted
replaced
4192:30ebe460e77a | 4193:ff24a06b3474 |
---|---|
1122 if (ssl_) | 1122 if (ssl_) |
1123 { | 1123 { |
1124 port += "s"; | 1124 port += "s"; |
1125 } | 1125 } |
1126 | 1126 |
1127 const char *options[] = { | 1127 std::vector<const char*> options; |
1128 // Set the TCP port for the HTTP server | 1128 |
1129 "listening_ports", port.c_str(), | 1129 // Set the TCP port for the HTTP server |
1130 options.push_back("listening_ports"); | |
1131 options.push_back(port.c_str()); | |
1130 | 1132 |
1131 // Optimization reported by Chris Hafey | 1133 // Optimization reported by Chris Hafey |
1132 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ | 1134 // https://groups.google.com/d/msg/orthanc-users/CKueKX0pJ9E/_UCbl8T-VjIJ |
1133 "enable_keep_alive", (keepAlive_ ? "yes" : "no"), | 1135 options.push_back("enable_keep_alive"); |
1136 options.push_back(keepAlive_ ? "yes" : "no"); | |
1134 | 1137 |
1135 #if ORTHANC_ENABLE_CIVETWEB == 1 | 1138 #if ORTHANC_ENABLE_CIVETWEB == 1 |
1136 // https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no | 1139 // https://github.com/civetweb/civetweb/blob/master/docs/UserManual.md#enable_keep_alive-no |
1137 "keep_alive_timeout_ms", (keepAlive_ ? "500" : "0"), | 1140 options.push_back("keep_alive_timeout_ms"); |
1141 options.push_back(keepAlive_ ? "500" : "0"); | |
1138 #endif | 1142 #endif |
1139 | 1143 |
1140 #if ORTHANC_ENABLE_CIVETWEB == 1 | 1144 #if ORTHANC_ENABLE_CIVETWEB == 1 |
1141 // Disable TCP Nagle's algorithm to maximize speed (this | 1145 // Disable TCP Nagle's algorithm to maximize speed (this |
1142 // option is not available in Mongoose). | 1146 // option is not available in Mongoose). |
1143 // https://groups.google.com/d/topic/civetweb/35HBR9seFjU/discussion | 1147 // https://groups.google.com/d/topic/civetweb/35HBR9seFjU/discussion |
1144 // https://eklitzke.org/the-caveats-of-tcp-nodelay | 1148 // https://eklitzke.org/the-caveats-of-tcp-nodelay |
1145 "tcp_nodelay", (tcpNoDelay_ ? "1" : "0"), | 1149 options.push_back("tcp_nodelay"); |
1146 #endif | 1150 options.push_back(tcpNoDelay_ ? "1" : "0"); |
1147 | 1151 #endif |
1148 // Set the number of threads | 1152 |
1149 "num_threads", numThreads.c_str(), | 1153 // Set the number of threads |
1154 options.push_back("num_threads"); | |
1155 options.push_back(numThreads.c_str()); | |
1150 | 1156 |
1151 // Set the timeout for the HTTP server | 1157 // Set the timeout for the HTTP server |
1152 "request_timeout_ms", requestTimeoutMilliseconds.c_str(), | 1158 options.push_back("request_timeout_ms"); |
1153 | 1159 options.push_back(requestTimeoutMilliseconds.c_str()); |
1154 // Set the client authentication | 1160 |
1155 "ssl_verify_peer", (sslVerifyPeers_ ? "yes" : "no"), | 1161 // Set the client authentication |
1162 options.push_back("ssl_verify_peer"); | |
1163 options.push_back(sslVerifyPeers_ ? "yes" : "no"); | |
1164 | |
1165 if (sslVerifyPeers_) | |
1166 { | |
1156 // Set the trusted client certificates (for X509 mutual authentication) | 1167 // Set the trusted client certificates (for X509 mutual authentication) |
1157 sslVerifyPeers_ ? "ssl_ca_file" : NULL, trustedClientCertificates_.c_str(), | 1168 options.push_back("ssl_ca_file"); |
1158 | 1169 options.push_back(trustedClientCertificates_.c_str()); |
1159 // Set the SSL certificate, if any. This must be the last option. | 1170 } |
1160 ssl_ ? "ssl_certificate" : NULL, | 1171 |
1161 certificate_.c_str(), | 1172 if (ssl_) |
1162 NULL | 1173 { |
1174 // Set the SSL certificate, if any | |
1175 options.push_back("ssl_certificate"); | |
1176 options.push_back(certificate_.c_str()); | |
1163 }; | 1177 }; |
1164 | 1178 |
1179 assert(options.size() % 2 == 0); | |
1180 options.push_back(NULL); | |
1181 | |
1165 #if MONGOOSE_USE_CALLBACKS == 0 | 1182 #if MONGOOSE_USE_CALLBACKS == 0 |
1166 pimpl_->context_ = mg_start(&Callback, this, options); | 1183 pimpl_->context_ = mg_start(&Callback, this, &options[0]); |
1167 | 1184 |
1168 #elif MONGOOSE_USE_CALLBACKS == 1 | 1185 #elif MONGOOSE_USE_CALLBACKS == 1 |
1169 struct mg_callbacks callbacks; | 1186 struct mg_callbacks callbacks; |
1170 memset(&callbacks, 0, sizeof(callbacks)); | 1187 memset(&callbacks, 0, sizeof(callbacks)); |
1171 callbacks.begin_request = Callback; | 1188 callbacks.begin_request = Callback; |
1172 pimpl_->context_ = mg_start(&callbacks, this, options); | 1189 pimpl_->context_ = mg_start(&callbacks, this, &options[0]); |
1173 | 1190 |
1174 #else | 1191 #else |
1175 # error Please set MONGOOSE_USE_CALLBACKS | 1192 # error Please set MONGOOSE_USE_CALLBACKS |
1176 #endif | 1193 #endif |
1177 | 1194 |