comparison 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
comparison
equal deleted inserted replaced
1518:eb46cc06389a 1519:8bd0d897763f
32 32
33 #include "../PrecompiledHeaders.h" 33 #include "../PrecompiledHeaders.h"
34 #include "HttpFileSender.h" 34 #include "HttpFileSender.h"
35 35
36 #include "../OrthancException.h" 36 #include "../OrthancException.h"
37 #include "../Toolbox.h"
37 38
38 #include <boost/lexical_cast.hpp> 39 #include <boost/lexical_cast.hpp>
39 40
40 namespace Orthanc 41 namespace Orthanc
41 { 42 {
42 void HttpFileSender::SendHeader(HttpOutput& output) 43 void HttpFileSender::SetFilename(const std::string& filename)
43 { 44 {
44 if (contentType_.size() > 0) 45 filename_ = filename;
46
47 if (contentType_.empty())
45 { 48 {
46 output.SetContentType(contentType_.c_str()); 49 contentType_ = Toolbox::AutodetectMimeType(filename);
47 } 50 }
48
49 if (downloadFilename_.size() > 0)
50 {
51 output.SetContentFilename(downloadFilename_.c_str());
52 }
53
54 output.SetContentLength(GetFileSize());
55 } 51 }
56 52
57 void HttpFileSender::Send(HttpOutput& output) 53
54 bool HttpFileSender::HasContentFilename(std::string& filename)
58 { 55 {
59 SendHeader(output); 56 if (!filename_.empty())
60
61 if (!SendData(output))
62 { 57 {
63 throw OrthancException(ErrorCode_InternalError); 58 filename = filename_;
64 //output.SendHeader(HttpStatus_500_InternalServerError); 59 }
60 }
61
62 std::string HttpFileSender::GetContentType()
63 {
64 if (contentType_.empty())
65 {
66 return "application/octet-stream";
67 }
68 else
69 {
70 return contentType_;
65 } 71 }
66 } 72 }
67 } 73 }