Mercurial > hg > orthanc
comparison Core/HttpServer/HttpOutput.cpp @ 2954:d924f9bb61cc
taking advantage of details in OrthancException
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Dec 2018 14:35:34 +0100 |
parents | 9d277f8ad698 |
children | 4e43e67f8ecf |
comparison
equal
deleted
inserted
replaced
2953:210d5afd8f2b | 2954:d924f9bb61cc |
---|---|
149 { | 149 { |
150 return; | 150 return; |
151 } | 151 } |
152 else | 152 else |
153 { | 153 { |
154 LOG(ERROR) << "Because of keep-alive connections, the entire body must be sent at once or Content-Length must be given"; | 154 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
155 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 155 "Because of keep-alive connections, the entire body must " |
156 "be sent at once or Content-Length must be given"); | |
156 } | 157 } |
157 } | 158 } |
158 | 159 |
159 if (state_ == State_WritingMultipart) | 160 if (state_ == State_WritingMultipart) |
160 { | 161 { |
196 } | 197 } |
197 | 198 |
198 if (hasContentLength_ && | 199 if (hasContentLength_ && |
199 contentPosition_ + length > contentLength_) | 200 contentPosition_ + length > contentLength_) |
200 { | 201 { |
201 LOG(ERROR) << "The body size exceeds what was declared with SetContentSize()"; | 202 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
202 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 203 "The body size exceeds what was declared with SetContentSize()"); |
203 } | 204 } |
204 | 205 |
205 if (length > 0) | 206 if (length > 0) |
206 { | 207 { |
207 stream_.Send(false, buffer, length); | 208 stream_.Send(false, buffer, length); |
231 { | 232 { |
232 state_ = State_Done; | 233 state_ = State_Done; |
233 } | 234 } |
234 else | 235 else |
235 { | 236 { |
236 LOG(ERROR) << "The body size has not reached what was declared with SetContentSize()"; | 237 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
237 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 238 "The body size has not reached what was declared with SetContentSize()"); |
238 } | 239 } |
239 | 240 |
240 break; | 241 break; |
241 | 242 |
242 case State_WritingMultipart: | 243 case State_WritingMultipart: |
243 LOG(ERROR) << "Cannot invoke CloseBody() with multipart outputs"; | 244 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
244 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 245 "Cannot invoke CloseBody() with multipart outputs"); |
245 | 246 |
246 case State_Done: | 247 case State_Done: |
247 return; // Ignore | 248 return; // Ignore |
248 | 249 |
249 default: | 250 default: |
294 { | 295 { |
295 if (status == HttpStatus_301_MovedPermanently || | 296 if (status == HttpStatus_301_MovedPermanently || |
296 status == HttpStatus_401_Unauthorized || | 297 status == HttpStatus_401_Unauthorized || |
297 status == HttpStatus_405_MethodNotAllowed) | 298 status == HttpStatus_405_MethodNotAllowed) |
298 { | 299 { |
299 LOG(ERROR) << "Please use the dedicated methods to this HTTP status code in HttpOutput"; | 300 throw OrthancException(ErrorCode_ParameterOutOfRange, |
300 throw OrthancException(ErrorCode_ParameterOutOfRange); | 301 "Please use the dedicated methods to this HTTP status code in HttpOutput"); |
301 } | 302 } |
302 | 303 |
303 stateMachine_.SetHttpStatus(status); | 304 stateMachine_.SetHttpStatus(status); |
304 stateMachine_.SendBody(message, messageSize); | 305 stateMachine_.SendBody(message, messageSize); |
305 } | 306 } |
406 throw OrthancException(ErrorCode_ParameterOutOfRange); | 407 throw OrthancException(ErrorCode_ParameterOutOfRange); |
407 } | 408 } |
408 | 409 |
409 if (keepAlive_) | 410 if (keepAlive_) |
410 { | 411 { |
411 LOG(ERROR) << "Multipart answers are not implemented together with keep-alive connections"; | 412 throw OrthancException(ErrorCode_NotImplemented, |
412 throw OrthancException(ErrorCode_NotImplemented); | 413 "Multipart answers are not implemented together with keep-alive connections"); |
413 } | 414 } |
414 | 415 |
415 if (state_ != State_WritingHeader) | 416 if (state_ != State_WritingHeader) |
416 { | 417 { |
417 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 418 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
431 for (std::list<std::string>::const_iterator | 432 for (std::list<std::string>::const_iterator |
432 it = headers_.begin(); it != headers_.end(); ++it) | 433 it = headers_.begin(); it != headers_.end(); ++it) |
433 { | 434 { |
434 if (!Toolbox::StartsWith(*it, "Set-Cookie: ")) | 435 if (!Toolbox::StartsWith(*it, "Set-Cookie: ")) |
435 { | 436 { |
436 LOG(ERROR) << "The only headers that can be set in multipart answers " | 437 throw OrthancException(ErrorCode_BadSequenceOfCalls, |
437 << "are Set-Cookie (here: " << *it << " is set)"; | 438 "The only headers that can be set in multipart answers " |
438 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 439 "are Set-Cookie (here: " + *it + " is set)"); |
439 } | 440 } |
440 | 441 |
441 header += *it; | 442 header += *it; |
442 } | 443 } |
443 | 444 |