Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpServer/HttpOutput.cpp @ 4298:db3932f9660d
abi continued
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Nov 2020 18:21:03 +0100 |
parents | 2d5209153b32 |
children | 6919242d2265 |
comparison
equal
deleted
inserted
replaced
4297:785a2713323e | 4298:db3932f9660d |
---|---|
280 return HttpCompression_None; | 280 return HttpCompression_None; |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 | 284 |
285 HttpOutput::HttpOutput(IHttpOutputStream &stream, | |
286 bool isKeepAlive) : | |
287 stateMachine_(stream, isKeepAlive), | |
288 isDeflateAllowed_(false), | |
289 isGzipAllowed_(false) | |
290 { | |
291 } | |
292 | |
293 void HttpOutput::SetDeflateAllowed(bool allowed) | |
294 { | |
295 isDeflateAllowed_ = allowed; | |
296 } | |
297 | |
298 bool HttpOutput::IsDeflateAllowed() const | |
299 { | |
300 return isDeflateAllowed_; | |
301 } | |
302 | |
303 void HttpOutput::SetGzipAllowed(bool allowed) | |
304 { | |
305 isGzipAllowed_ = allowed; | |
306 } | |
307 | |
308 bool HttpOutput::IsGzipAllowed() const | |
309 { | |
310 return isGzipAllowed_; | |
311 } | |
312 | |
313 | |
285 void HttpOutput::SendMethodNotAllowed(const std::string& allowed) | 314 void HttpOutput::SendMethodNotAllowed(const std::string& allowed) |
286 { | 315 { |
287 stateMachine_.ClearHeaders(); | 316 stateMachine_.ClearHeaders(); |
288 stateMachine_.SetHttpStatus(HttpStatus_405_MethodNotAllowed); | 317 stateMachine_.SetHttpStatus(HttpStatus_405_MethodNotAllowed); |
289 stateMachine_.AddHeader("Allow", allowed); | 318 stateMachine_.AddHeader("Allow", allowed); |
305 | 334 |
306 stateMachine_.SetHttpStatus(status); | 335 stateMachine_.SetHttpStatus(status); |
307 stateMachine_.SendBody(message, messageSize); | 336 stateMachine_.SendBody(message, messageSize); |
308 } | 337 } |
309 | 338 |
339 void HttpOutput::SendStatus(HttpStatus status) | |
340 { | |
341 SendStatus(status, NULL, 0); | |
342 } | |
343 | |
344 void HttpOutput::SendStatus(HttpStatus status, const std::string &message) | |
345 { | |
346 SendStatus(status, message.c_str(), message.size()); | |
347 } | |
348 | |
349 void HttpOutput::SetContentType(MimeType contentType) | |
350 { | |
351 stateMachine_.SetContentType(EnumerationToString(contentType)); | |
352 } | |
353 | |
354 void HttpOutput::SetContentType(const std::string &contentType) | |
355 { | |
356 stateMachine_.SetContentType(contentType.c_str()); | |
357 } | |
358 | |
359 void HttpOutput::SetContentFilename(const char *filename) | |
360 { | |
361 stateMachine_.SetContentFilename(filename); | |
362 } | |
363 | |
364 void HttpOutput::SetCookie(const std::string &cookie, const std::string &value) | |
365 { | |
366 stateMachine_.SetCookie(cookie, value); | |
367 } | |
368 | |
369 void HttpOutput::AddHeader(const std::string &key, const std::string &value) | |
370 { | |
371 stateMachine_.AddHeader(key, value); | |
372 } | |
373 | |
310 | 374 |
311 void HttpOutput::Redirect(const std::string& path) | 375 void HttpOutput::Redirect(const std::string& path) |
312 { | 376 { |
313 stateMachine_.ClearHeaders(); | 377 stateMachine_.ClearHeaders(); |
314 stateMachine_.SetHttpStatus(HttpStatus_301_MovedPermanently); | 378 stateMachine_.SetHttpStatus(HttpStatus_301_MovedPermanently); |
323 stateMachine_.SetHttpStatus(HttpStatus_401_Unauthorized); | 387 stateMachine_.SetHttpStatus(HttpStatus_401_Unauthorized); |
324 stateMachine_.AddHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); | 388 stateMachine_.AddHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\""); |
325 stateMachine_.SendBody(NULL, 0); | 389 stateMachine_.SendBody(NULL, 0); |
326 } | 390 } |
327 | 391 |
392 void HttpOutput::StartMultipart(const std::string &subType, const std::string &contentType) | |
393 { | |
394 stateMachine_.StartMultipart(subType, contentType); | |
395 } | |
396 | |
397 void HttpOutput::SendMultipartItem(const void *item, | |
398 size_t size, | |
399 const std::map<std::string, std::string> &headers) | |
400 { | |
401 stateMachine_.SendMultipartItem(item, size, headers); | |
402 } | |
403 | |
404 void HttpOutput::CloseMultipart() | |
405 { | |
406 stateMachine_.CloseMultipart(); | |
407 } | |
408 | |
409 bool HttpOutput::IsWritingMultipart() const | |
410 { | |
411 return stateMachine_.GetState() == StateMachine::State_WritingMultipart; | |
412 } | |
413 | |
328 | 414 |
329 void HttpOutput::Answer(const void* buffer, | 415 void HttpOutput::Answer(const void* buffer, |
330 size_t length) | 416 size_t length) |
331 { | 417 { |
332 if (length == 0) | 418 if (length == 0) |
333 { | 419 { |
334 AnswerEmpty(); | 420 AnswerEmpty(); |