Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/Core/HttpServer/MongooseServer.cpp Tue Aug 11 08:53:47 2015 +0200 +++ b/Core/HttpServer/MongooseServer.cpp Tue Aug 11 10:32:34 2015 +0200 @@ -548,6 +548,34 @@ } + static void ConfigureHttpCompression(HttpOutput& output, + const IHttpHandler::Arguments& headers) + { + // Look if the client wishes HTTP compression + // https://en.wikipedia.org/wiki/HTTP_compression + IHttpHandler::Arguments::const_iterator it = headers.find("accept-encoding"); + if (it != headers.end()) + { + std::vector<std::string> encodings; + Toolbox::TokenizeString(encodings, it->second, ','); + + for (size_t i = 0; i < encodings.size(); i++) + { + std::string s = Toolbox::StripSpaces(encodings[i]); + + if (s == "deflate") + { + output.SetDeflateAllowed(true); + } + else if (s == "gzip") + { + output.SetGzipAllowed(true); + } + } + } + } + + static void InternalCallback(struct mg_connection *connection, const struct mg_request_info *request) { @@ -574,6 +602,11 @@ headers.insert(std::make_pair(name, request->http_headers[i].value)); } + if (that->IsHttpCompressionEnabled()) + { + ConfigureHttpCompression(output, headers); + } + // Extract the GET arguments IHttpHandler::GetArguments argumentsGET; @@ -799,6 +832,7 @@ port_ = 8000; filter_ = NULL; keepAlive_ = false; + httpCompression_ = true; #if ORTHANC_SSL_ENABLED == 1 // Check for the Heartbleed exploit @@ -942,6 +976,12 @@ remoteAllowed_ = allowed; } + void MongooseServer::SetHttpCompressionEnabled(bool enabled) + { + Stop(); + httpCompression_ = enabled; + } + void MongooseServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) { Stop();