comparison OrthancFramework/Sources/HttpServer/HttpServer.cpp @ 4295:90f91b78d708

applied log categories
author Alain Mazy <alain@mazy.be>
date Thu, 05 Nov 2020 12:01:11 +0100
parents 0923247e69f6
children db3932f9660d
comparison
equal deleted inserted replaced
4294:0923247e69f6 4295:90f91b78d708
632 if (overriden.size() > 0) 632 if (overriden.size() > 0)
633 { 633 {
634 // A faking has been done within this request 634 // A faking has been done within this request
635 Toolbox::ToUpperCase(overriden); 635 Toolbox::ToUpperCase(overriden);
636 636
637 LOG(INFO) << "HTTP method faking has been detected for " << overriden; 637 CLOG(INFO, HTTP) << "HTTP method faking has been detected for " << overriden;
638 638
639 if (overriden == "PUT") 639 if (overriden == "PUT")
640 { 640 {
641 method = HttpMethod_Put; 641 method = HttpMethod_Put;
642 return true; 642 return true;
710 710
711 # if CIVETWEB_HAS_WEBDAV_WRITING == 0 711 # if CIVETWEB_HAS_WEBDAV_WRITING == 0
712 static void AnswerWebDavReadOnly(HttpOutput& output, 712 static void AnswerWebDavReadOnly(HttpOutput& output,
713 const std::string& uri) 713 const std::string& uri)
714 { 714 {
715 LOG(ERROR) << "Orthanc was compiled without support for read-write access to WebDAV: " << uri; 715 CLOG(ERROR, HTTP) << "Orthanc was compiled without support for read-write access to WebDAV: " << uri;
716 output.SendStatus(HttpStatus_403_Forbidden); 716 output.SendStatus(HttpStatus_403_Forbidden);
717 } 717 }
718 # endif 718 # endif
719 719
720 static bool HandleWebDav(HttpOutput& output, 720 static bool HandleWebDav(HttpOutput& output,
944 output.SendStatus(HttpStatus_403_Forbidden); 944 output.SendStatus(HttpStatus_403_Forbidden);
945 } 945 }
946 } 946 }
947 else 947 else
948 { 948 {
949 LOG(ERROR) << "Cannot read the content of a file to be stored in WebDAV"; 949 CLOG(ERROR, HTTP) << "Cannot read the content of a file to be stored in WebDAV";
950 output.SendStatus(HttpStatus_400_BadRequest); 950 output.SendStatus(HttpStatus_400_BadRequest);
951 } 951 }
952 #else 952 #else
953 AnswerWebDavReadOnly(output, uri); 953 AnswerWebDavReadOnly(output, uri);
954 #endif 954 #endif
1160 HttpMethod filterMethod; 1160 HttpMethod filterMethod;
1161 1161
1162 1162
1163 if (ExtractMethod(method, request, headers, argumentsGET)) 1163 if (ExtractMethod(method, request, headers, argumentsGET))
1164 { 1164 {
1165 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); 1165 CLOG(INFO, HTTP) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri);
1166 filterMethod = method; 1166 filterMethod = method;
1167 } 1167 }
1168 #if ORTHANC_ENABLE_PUGIXML == 1 1168 #if ORTHANC_ENABLE_PUGIXML == 1
1169 else if (!strcmp(request->request_method, "OPTIONS") || 1169 else if (!strcmp(request->request_method, "OPTIONS") ||
1170 !strcmp(request->request_method, "PROPFIND") || 1170 !strcmp(request->request_method, "PROPFIND") ||
1171 !strcmp(request->request_method, "HEAD")) 1171 !strcmp(request->request_method, "HEAD"))
1172 { 1172 {
1173 LOG(INFO) << "Incoming read-only WebDAV request: " 1173 CLOG(INFO, HTTP) << "Incoming read-only WebDAV request: "
1174 << request->request_method << " " << requestUri; 1174 << request->request_method << " " << requestUri;
1175 filterMethod = HttpMethod_Get; 1175 filterMethod = HttpMethod_Get;
1176 isWebDav = true; 1176 isWebDav = true;
1177 } 1177 }
1178 else if (!strcmp(request->request_method, "PROPPATCH") || 1178 else if (!strcmp(request->request_method, "PROPPATCH") ||
1179 !strcmp(request->request_method, "LOCK") || 1179 !strcmp(request->request_method, "LOCK") ||
1180 !strcmp(request->request_method, "UNLOCK") || 1180 !strcmp(request->request_method, "UNLOCK") ||
1181 !strcmp(request->request_method, "MKCOL")) 1181 !strcmp(request->request_method, "MKCOL"))
1182 { 1182 {
1183 LOG(INFO) << "Incoming read-write WebDAV request: " 1183 CLOG(INFO, HTTP) << "Incoming read-write WebDAV request: "
1184 << request->request_method << " " << requestUri; 1184 << request->request_method << " " << requestUri;
1185 filterMethod = HttpMethod_Put; 1185 filterMethod = HttpMethod_Put;
1186 isWebDav = true; 1186 isWebDav = true;
1187 } 1187 }
1188 #endif /* ORTHANC_ENABLE_PUGIXML == 1 */ 1188 #endif /* ORTHANC_ENABLE_PUGIXML == 1 */
1189 else 1189 else
1190 { 1190 {
1191 LOG(INFO) << "Unknown HTTP method: " << request->request_method; 1191 CLOG(INFO, HTTP) << "Unknown HTTP method: " << request->request_method;
1192 output.SendStatus(HttpStatus_400_BadRequest); 1192 output.SendStatus(HttpStatus_400_BadRequest);
1193 return; 1193 return;
1194 } 1194 }
1195 1195
1196 1196
1216 { 1216 {
1217 return; 1217 return;
1218 } 1218 }
1219 else if (isWebDav) 1219 else if (isWebDav)
1220 { 1220 {
1221 LOG(INFO) << "No WebDAV bucket is registered against URI: " 1221 CLOG(INFO, HTTP) << "No WebDAV bucket is registered against URI: "
1222 << request->request_method << " " << requestUri; 1222 << request->request_method << " " << requestUri;
1223 output.SendStatus(HttpStatus_404_NotFound); 1223 output.SendStatus(HttpStatus_404_NotFound);
1224 return; 1224 return;
1225 } 1225 }
1226 #endif 1226 #endif
1227 1227
1399 // Using this candidate handler results in an exception 1399 // Using this candidate handler results in an exception
1400 try 1400 try
1401 { 1401 {
1402 if (server->GetExceptionFormatter() == NULL) 1402 if (server->GetExceptionFormatter() == NULL)
1403 { 1403 {
1404 LOG(ERROR) << "Exception in the HTTP handler: " << e.What(); 1404 CLOG(ERROR, HTTP) << "Exception in the HTTP handler: " << e.What();
1405 output.SendStatus(e.GetHttpStatus()); 1405 output.SendStatus(e.GetHttpStatus());
1406 } 1406 }
1407 else 1407 else
1408 { 1408 {
1409 server->GetExceptionFormatter()->Format(output, e, method, requestUri); 1409 server->GetExceptionFormatter()->Format(output, e, method, requestUri);
1417 } 1417 }
1418 } 1418 }
1419 catch (...) 1419 catch (...)
1420 { 1420 {
1421 // We should never arrive at this point, where it is even impossible to send an answer 1421 // We should never arrive at this point, where it is even impossible to send an answer
1422 LOG(ERROR) << "Catastrophic error inside the HTTP server, giving up"; 1422 CLOG(ERROR, HTTP) << "Catastrophic error inside the HTTP server, giving up";
1423 } 1423 }
1424 } 1424 }
1425 1425
1426 1426
1427 #if MONGOOSE_USE_CALLBACKS == 0 1427 #if MONGOOSE_USE_CALLBACKS == 0
1482 threadsCount_(50), // Default value in mongoose 1482 threadsCount_(50), // Default value in mongoose
1483 tcpNoDelay_(true), 1483 tcpNoDelay_(true),
1484 requestTimeout_(30) // Default value in mongoose/civetweb (30 seconds) 1484 requestTimeout_(30) // Default value in mongoose/civetweb (30 seconds)
1485 { 1485 {
1486 #if ORTHANC_ENABLE_MONGOOSE == 1 1486 #if ORTHANC_ENABLE_MONGOOSE == 1
1487 LOG(INFO) << "This Orthanc server uses Mongoose as its embedded HTTP server"; 1487 CLOG(INFO, HTTP) << "This Orthanc server uses Mongoose as its embedded HTTP server";
1488 #endif 1488 #endif
1489 1489
1490 #if ORTHANC_ENABLE_CIVETWEB == 1 1490 #if ORTHANC_ENABLE_CIVETWEB == 1
1491 LOG(INFO) << "This Orthanc server uses CivetWeb as its embedded HTTP server"; 1491 CLOG(INFO, HTTP) << "This Orthanc server uses CivetWeb as its embedded HTTP server";
1492 #endif 1492 #endif
1493 1493
1494 #if ORTHANC_ENABLE_SSL == 1 1494 #if ORTHANC_ENABLE_SSL == 1
1495 // Check for the Heartbleed exploit 1495 // Check for the Heartbleed exploit
1496 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug 1496 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug
1497 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ && 1497 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ &&
1498 OPENSSL_VERSION_NUMBER >= 0x1000100fL /* openssl-1.0.1 */) 1498 OPENSSL_VERSION_NUMBER >= 0x1000100fL /* openssl-1.0.1 */)
1499 { 1499 {
1500 LOG(WARNING) << "This version of OpenSSL is vulnerable to the Heartbleed exploit"; 1500 CLOG(WARNING, HTTP) << "This version of OpenSSL is vulnerable to the Heartbleed exploit";
1501 } 1501 }
1502 #endif 1502 #endif
1503 } 1503 }
1504 1504
1505 1505
1524 } 1524 }
1525 1525
1526 void HttpServer::Start() 1526 void HttpServer::Start()
1527 { 1527 {
1528 #if ORTHANC_ENABLE_MONGOOSE == 1 1528 #if ORTHANC_ENABLE_MONGOOSE == 1
1529 LOG(INFO) << "Starting embedded Web server using Mongoose"; 1529 CLOG(INFO, HTTP) << "Starting embedded Web server using Mongoose";
1530 #elif ORTHANC_ENABLE_CIVETWEB == 1 1530 #elif ORTHANC_ENABLE_CIVETWEB == 1
1531 LOG(INFO) << "Starting embedded Web server using Civetweb"; 1531 CLOG(INFO, HTTP) << "Starting embedded Web server using Civetweb";
1532 #else 1532 #else
1533 # error 1533 # error
1534 #endif 1534 #endif
1535 1535
1536 if (!IsRunning()) 1536 if (!IsRunning())
1627 else 1627 else
1628 { 1628 {
1629 isSslError = true; 1629 isSslError = true;
1630 char message[1024]; 1630 char message[1024];
1631 ERR_error_string_n(code, message, sizeof(message) - 1); 1631 ERR_error_string_n(code, message, sizeof(message) - 1);
1632 LOG(ERROR) << "OpenSSL error: " << message; 1632 CLOG(ERROR, HTTP) << "OpenSSL error: " << message;
1633 } 1633 }
1634 } 1634 }
1635 #endif 1635 #endif
1636 1636
1637 if (isSslError) 1637 if (isSslError)
1651 assert(it->second != NULL); 1651 assert(it->second != NULL);
1652 it->second->Start(); 1652 it->second->Start();
1653 } 1653 }
1654 #endif 1654 #endif
1655 1655
1656 LOG(WARNING) << "HTTP server listening on port: " << GetPortNumber() 1656 CLOG(WARNING, HTTP) << "HTTP server listening on port: " << GetPortNumber()
1657 << " (HTTPS encryption is " 1657 << " (HTTPS encryption is "
1658 << (IsSslEnabled() ? "enabled" : "disabled") 1658 << (IsSslEnabled() ? "enabled" : "disabled")
1659 << ", remote access is " 1659 << ", remote access is "
1660 << (IsRemoteAccessAllowed() ? "" : "not ") 1660 << (IsRemoteAccessAllowed() ? "" : "not ")
1661 << "allowed)"; 1661 << "allowed)";
1662 } 1662 }
1663 } 1663 }
1664 1664
1665 void HttpServer::Stop() 1665 void HttpServer::Stop()
1666 { 1666 {
1737 1737
1738 void HttpServer::SetKeepAliveEnabled(bool enabled) 1738 void HttpServer::SetKeepAliveEnabled(bool enabled)
1739 { 1739 {
1740 Stop(); 1740 Stop();
1741 keepAlive_ = enabled; 1741 keepAlive_ = enabled;
1742 LOG(INFO) << "HTTP keep alive is " << (enabled ? "enabled" : "disabled"); 1742 CLOG(INFO, HTTP) << "HTTP keep alive is " << (enabled ? "enabled" : "disabled");
1743 1743
1744 #if ORTHANC_ENABLE_MONGOOSE == 1 1744 #if ORTHANC_ENABLE_MONGOOSE == 1
1745 if (enabled) 1745 if (enabled)
1746 { 1746 {
1747 LOG(WARNING) << "You should disable HTTP keep alive, as you are using Mongoose"; 1747 CLOG(WARNING, HTTP) << "You should disable HTTP keep alive, as you are using Mongoose";
1748 } 1748 }
1749 #endif 1749 #endif
1750 } 1750 }
1751 1751
1752 1752
1776 1776
1777 void HttpServer::SetHttpCompressionEnabled(bool enabled) 1777 void HttpServer::SetHttpCompressionEnabled(bool enabled)
1778 { 1778 {
1779 Stop(); 1779 Stop();
1780 httpCompression_ = enabled; 1780 httpCompression_ = enabled;
1781 LOG(WARNING) << "HTTP compression is " << (enabled ? "enabled" : "disabled"); 1781 CLOG(WARNING, HTTP) << "HTTP compression is " << (enabled ? "enabled" : "disabled");
1782 } 1782 }
1783 1783
1784 void HttpServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) 1784 void HttpServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter)
1785 { 1785 {
1786 Stop(); 1786 Stop();
1827 } 1827 }
1828 1828
1829 Stop(); 1829 Stop();
1830 threadsCount_ = threads; 1830 threadsCount_ = threads;
1831 1831
1832 LOG(INFO) << "The embedded HTTP server will use " << threads << " threads"; 1832 CLOG(INFO, HTTP) << "The embedded HTTP server will use " << threads << " threads";
1833 } 1833 }
1834 1834
1835 1835
1836 void HttpServer::SetTcpNoDelay(bool tcpNoDelay) 1836 void HttpServer::SetTcpNoDelay(bool tcpNoDelay)
1837 { 1837 {
1838 Stop(); 1838 Stop();
1839 tcpNoDelay_ = tcpNoDelay; 1839 tcpNoDelay_ = tcpNoDelay;
1840 LOG(INFO) << "TCP_NODELAY for the HTTP sockets is set to " 1840 CLOG(INFO, HTTP) << "TCP_NODELAY for the HTTP sockets is set to "
1841 << (tcpNoDelay ? "true" : "false"); 1841 << (tcpNoDelay ? "true" : "false");
1842 } 1842 }
1843 1843
1844 1844
1845 void HttpServer::SetRequestTimeout(unsigned int seconds) 1845 void HttpServer::SetRequestTimeout(unsigned int seconds)
1846 { 1846 {
1850 "Request timeout must be a stricly positive integer"); 1850 "Request timeout must be a stricly positive integer");
1851 } 1851 }
1852 1852
1853 Stop(); 1853 Stop();
1854 requestTimeout_ = seconds; 1854 requestTimeout_ = seconds;
1855 LOG(INFO) << "Request timeout in the HTTP server is set to " << seconds << " seconds"; 1855 CLOG(INFO, HTTP) << "Request timeout in the HTTP server is set to " << seconds << " seconds";
1856 } 1856 }
1857 1857
1858 1858
1859 #if ORTHANC_ENABLE_PUGIXML == 1 1859 #if ORTHANC_ENABLE_PUGIXML == 1
1860 void HttpServer::Register(const std::vector<std::string>& root, 1860 void HttpServer::Register(const std::vector<std::string>& root,
1870 Stop(); 1870 Stop();
1871 1871
1872 #if CIVETWEB_HAS_WEBDAV_WRITING == 0 1872 #if CIVETWEB_HAS_WEBDAV_WRITING == 0
1873 if (webDavBuckets_.size() == 0) 1873 if (webDavBuckets_.size() == 0)
1874 { 1874 {
1875 LOG(WARNING) << "Your version of the Orthanc framework was compiled " 1875 CLOG(WARNING, HTTP) << "Your version of the Orthanc framework was compiled "
1876 << "without support for writing into WebDAV collections"; 1876 << "without support for writing into WebDAV collections";
1877 } 1877 }
1878 #endif 1878 #endif
1879 1879
1880 const std::string s = Toolbox::FlattenUri(root); 1880 const std::string s = Toolbox::FlattenUri(root);
1881 1881
1884 throw OrthancException(ErrorCode_ParameterOutOfRange, 1884 throw OrthancException(ErrorCode_ParameterOutOfRange,
1885 "Cannot register two WebDAV buckets at the same root: " + s); 1885 "Cannot register two WebDAV buckets at the same root: " + s);
1886 } 1886 }
1887 else 1887 else
1888 { 1888 {
1889 LOG(INFO) << "Branching WebDAV bucket at: " << s; 1889 CLOG(INFO, HTTP) << "Branching WebDAV bucket at: " << s;
1890 webDavBuckets_[s] = protection.release(); 1890 webDavBuckets_[s] = protection.release();
1891 } 1891 }
1892 } 1892 }
1893 #endif 1893 #endif
1894 } 1894 }