diff Core/HttpServer/HttpFileSender.cpp @ 1519:8bd0d897763f

refactoring: IHttpStreamAnswer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2015 13:15:16 +0200
parents 6e7e5ed91c2d
children f938f7779bcb
line wrap: on
line diff
--- a/Core/HttpServer/HttpFileSender.cpp	Tue Aug 11 10:36:05 2015 +0200
+++ b/Core/HttpServer/HttpFileSender.cpp	Tue Aug 11 13:15:16 2015 +0200
@@ -34,34 +34,40 @@
 #include "HttpFileSender.h"
 
 #include "../OrthancException.h"
+#include "../Toolbox.h"
 
 #include <boost/lexical_cast.hpp>
 
 namespace Orthanc
 {
-  void HttpFileSender::SendHeader(HttpOutput& output)
+  void HttpFileSender::SetFilename(const std::string& filename)
   {
-    if (contentType_.size() > 0)
-    {
-      output.SetContentType(contentType_.c_str());
-    }
+    filename_ = filename;
 
-    if (downloadFilename_.size() > 0)
+    if (contentType_.empty())
     {
-      output.SetContentFilename(downloadFilename_.c_str());
+      contentType_ = Toolbox::AutodetectMimeType(filename);
     }
-
-    output.SetContentLength(GetFileSize());
   }
 
-  void HttpFileSender::Send(HttpOutput& output)
+
+  bool HttpFileSender::HasContentFilename(std::string& filename)
   {
-    SendHeader(output);
-
-    if (!SendData(output))
+    if (!filename_.empty())
     {
-      throw OrthancException(ErrorCode_InternalError);
-      //output.SendHeader(HttpStatus_500_InternalServerError);
+      filename = filename_;
+    }
+  }
+    
+  std::string HttpFileSender::GetContentType()
+  {
+    if (contentType_.empty())
+    {
+      return "application/octet-stream";
+    }
+    else
+    {
+      return contentType_;
     }
   }
 }