diff Core/HttpServer/HttpOutput.cpp @ 1517:4f8c8ef114db

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2015 10:32:34 +0200
parents d73a2178b319
children 8bd0d897763f
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp	Tue Aug 11 08:53:47 2015 +0200
+++ b/Core/HttpServer/HttpOutput.cpp	Tue Aug 11 10:32:34 2015 +0200
@@ -215,6 +215,33 @@
   }
 
 
+  HttpCompression HttpOutput::GetPreferredCompression(size_t bodySize) const
+  {
+#if 0
+    // TODO Do not compress small files?
+    if (bodySize < 512)
+    {
+      return HttpCompression_None;
+    }
+#endif
+
+    // Prefer "gzip" over "deflate" if the choice is offered
+
+    if (isGzipAllowed_)
+    {
+      return HttpCompression_Gzip;
+    }
+    else if (isDeflateAllowed_)
+    {
+      return HttpCompression_Deflate;
+    }
+    else
+    {
+      return HttpCompression_None;
+    }
+  }
+
+
   void HttpOutput::SendMethodNotAllowed(const std::string& allowed)
   {
     stateMachine_.ClearHeaders();
@@ -259,8 +286,7 @@
   }
 
   void HttpOutput::SendBody(const void* buffer, 
-                            size_t length,
-                            HttpCompression compression)
+                            size_t length)
   {
     if (length == 0)
     {
@@ -268,6 +294,8 @@
     }
     else
     {
+      HttpCompression compression = GetPreferredCompression(length);
+
       switch (compression)
       {
         case HttpCompression_None:
@@ -318,10 +346,9 @@
     }
   }
 
-  void HttpOutput::SendBody(const std::string& str,
-                            HttpCompression compression)
+  void HttpOutput::SendBody(const std::string& str)
   {
-    SendBody(str.size() == 0 ? NULL : str.c_str(), str.size(), compression);
+    SendBody(str.size() == 0 ? NULL : str.c_str(), str.size());
   }
 
   void HttpOutput::SendBody()