comparison Core/HttpServer/MongooseServer.cpp @ 1517:4f8c8ef114db

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2015 10:32:34 +0200
parents f967bdf8534e
children eb46cc06389a
comparison
equal deleted inserted replaced
1516:f09f5d3225a7 1517:4f8c8ef114db
546 546
547 return true; 547 return true;
548 } 548 }
549 549
550 550
551 static void ConfigureHttpCompression(HttpOutput& output,
552 const IHttpHandler::Arguments& headers)
553 {
554 // Look if the client wishes HTTP compression
555 // https://en.wikipedia.org/wiki/HTTP_compression
556 IHttpHandler::Arguments::const_iterator it = headers.find("accept-encoding");
557 if (it != headers.end())
558 {
559 std::vector<std::string> encodings;
560 Toolbox::TokenizeString(encodings, it->second, ',');
561
562 for (size_t i = 0; i < encodings.size(); i++)
563 {
564 std::string s = Toolbox::StripSpaces(encodings[i]);
565
566 if (s == "deflate")
567 {
568 output.SetDeflateAllowed(true);
569 }
570 else if (s == "gzip")
571 {
572 output.SetGzipAllowed(true);
573 }
574 }
575 }
576 }
577
578
551 static void InternalCallback(struct mg_connection *connection, 579 static void InternalCallback(struct mg_connection *connection,
552 const struct mg_request_info *request) 580 const struct mg_request_info *request)
553 { 581 {
554 MongooseServer* that = reinterpret_cast<MongooseServer*>(request->user_data); 582 MongooseServer* that = reinterpret_cast<MongooseServer*>(request->user_data);
555 583
570 for (int i = 0; i < request->num_headers; i++) 598 for (int i = 0; i < request->num_headers; i++)
571 { 599 {
572 std::string name = request->http_headers[i].name; 600 std::string name = request->http_headers[i].name;
573 std::transform(name.begin(), name.end(), name.begin(), ::tolower); 601 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
574 headers.insert(std::make_pair(name, request->http_headers[i].value)); 602 headers.insert(std::make_pair(name, request->http_headers[i].value));
603 }
604
605 if (that->IsHttpCompressionEnabled())
606 {
607 ConfigureHttpCompression(output, headers);
575 } 608 }
576 609
577 610
578 // Extract the GET arguments 611 // Extract the GET arguments
579 IHttpHandler::GetArguments argumentsGET; 612 IHttpHandler::GetArguments argumentsGET;
797 authentication_ = false; 830 authentication_ = false;
798 ssl_ = false; 831 ssl_ = false;
799 port_ = 8000; 832 port_ = 8000;
800 filter_ = NULL; 833 filter_ = NULL;
801 keepAlive_ = false; 834 keepAlive_ = false;
835 httpCompression_ = true;
802 836
803 #if ORTHANC_SSL_ENABLED == 1 837 #if ORTHANC_SSL_ENABLED == 1
804 // Check for the Heartbleed exploit 838 // Check for the Heartbleed exploit
805 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug 839 // https://en.wikipedia.org/wiki/OpenSSL#Heartbleed_bug
806 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ && 840 if (OPENSSL_VERSION_NUMBER < 0x1000107fL /* openssl-1.0.1g */ &&
940 { 974 {
941 Stop(); 975 Stop();
942 remoteAllowed_ = allowed; 976 remoteAllowed_ = allowed;
943 } 977 }
944 978
979 void MongooseServer::SetHttpCompressionEnabled(bool enabled)
980 {
981 Stop();
982 httpCompression_ = enabled;
983 }
984
945 void MongooseServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) 985 void MongooseServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter)
946 { 986 {
947 Stop(); 987 Stop();
948 filter_ = &filter; 988 filter_ = &filter;
949 } 989 }