Mercurial > hg > orthanc
comparison Core/HttpServer/HttpOutput.h @ 1430:ad94a3583b07
Plugins can send answers as multipart messages
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 29 Jun 2015 17:47:34 +0200 |
parents | 6e7e5ed91c2d |
children | f3672356c121 |
comparison
equal
deleted
inserted
replaced
1429:7366a0bdda6a | 1430:ad94a3583b07 |
---|---|
36 #include <string> | 36 #include <string> |
37 #include <stdint.h> | 37 #include <stdint.h> |
38 #include "../Enumerations.h" | 38 #include "../Enumerations.h" |
39 #include "IHttpOutputStream.h" | 39 #include "IHttpOutputStream.h" |
40 #include "HttpHandler.h" | 40 #include "HttpHandler.h" |
41 #include "../Uuid.h" | |
41 | 42 |
42 namespace Orthanc | 43 namespace Orthanc |
43 { | 44 { |
44 class HttpOutput : public boost::noncopyable | 45 class HttpOutput : public boost::noncopyable |
45 { | 46 { |
46 private: | 47 private: |
47 typedef std::list< std::pair<std::string, std::string> > Header; | 48 typedef std::list< std::pair<std::string, std::string> > Header; |
48 | 49 |
49 class StateMachine : public boost::noncopyable | 50 class StateMachine : public boost::noncopyable |
50 { | 51 { |
51 private: | 52 public: |
52 enum State | 53 enum State |
53 { | 54 { |
54 State_WritingHeader, | 55 State_WritingHeader, |
55 State_WritingBody, | 56 State_WritingBody, |
57 State_WritingMultipart, | |
56 State_Done | 58 State_Done |
57 }; | 59 }; |
58 | 60 |
61 private: | |
59 IHttpOutputStream& stream_; | 62 IHttpOutputStream& stream_; |
60 State state_; | 63 State state_; |
61 | 64 |
62 HttpStatus status_; | 65 HttpStatus status_; |
63 bool hasContentLength_; | 66 bool hasContentLength_; |
64 uint64_t contentLength_; | 67 uint64_t contentLength_; |
65 uint64_t contentPosition_; | 68 uint64_t contentPosition_; |
66 bool keepAlive_; | 69 bool keepAlive_; |
67 std::list<std::string> headers_; | 70 std::list<std::string> headers_; |
71 | |
72 std::string multipartBoundary_; | |
73 std::string multipartContentType_; | |
68 | 74 |
69 public: | 75 public: |
70 StateMachine(IHttpOutputStream& stream, | 76 StateMachine(IHttpOutputStream& stream, |
71 bool isKeepAlive); | 77 bool isKeepAlive); |
72 | 78 |
87 const std::string& value); | 93 const std::string& value); |
88 | 94 |
89 void ClearHeaders(); | 95 void ClearHeaders(); |
90 | 96 |
91 void SendBody(const void* buffer, size_t length); | 97 void SendBody(const void* buffer, size_t length); |
98 | |
99 void StartMultipart(const std::string& subType, | |
100 const std::string& contentType); | |
101 | |
102 void SendMultipartItem(const void* item, size_t length); | |
103 | |
104 void CloseMultipart(); | |
105 | |
106 State GetState() const | |
107 { | |
108 return state_; | |
109 } | |
92 }; | 110 }; |
93 | 111 |
94 StateMachine stateMachine_; | 112 StateMachine stateMachine_; |
95 | 113 |
96 public: | 114 public: |
138 void SendMethodNotAllowed(const std::string& allowed); | 156 void SendMethodNotAllowed(const std::string& allowed); |
139 | 157 |
140 void Redirect(const std::string& path); | 158 void Redirect(const std::string& path); |
141 | 159 |
142 void SendUnauthorized(const std::string& realm); | 160 void SendUnauthorized(const std::string& realm); |
161 | |
162 void StartMultipart(const std::string& subType, | |
163 const std::string& contentType) | |
164 { | |
165 stateMachine_.StartMultipart(subType, contentType); | |
166 } | |
167 | |
168 void SendMultipartItem(const std::string& item); | |
169 | |
170 void SendMultipartItem(const void* item, size_t size) | |
171 { | |
172 stateMachine_.SendMultipartItem(item, size); | |
173 } | |
174 | |
175 void CloseMultipart() | |
176 { | |
177 stateMachine_.CloseMultipart(); | |
178 } | |
179 | |
180 bool IsWritingMultipart() const | |
181 { | |
182 return stateMachine_.GetState() == StateMachine::State_WritingMultipart; | |
183 } | |
143 }; | 184 }; |
144 } | 185 } |