comparison Core/HttpServer/HttpOutput.h @ 908:e078ea944089 plugins

refactoring HttpOutput
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Jun 2014 17:47:39 +0200
parents 2d0a347e8cfc
children 28a52982196e
comparison
equal deleted inserted replaced
907:9b8298234254 908:e078ea944089
34 34
35 #include <list> 35 #include <list>
36 #include <string> 36 #include <string>
37 #include <stdint.h> 37 #include <stdint.h>
38 #include "../Enumerations.h" 38 #include "../Enumerations.h"
39 #include "HttpOutputStream.h"
39 #include "HttpHandler.h" 40 #include "HttpHandler.h"
40 41
41 namespace Orthanc 42 namespace Orthanc
42 { 43 {
43 class HttpOutput 44 class HttpOutput
44 { 45 {
45 private: 46 private:
46 typedef std::list< std::pair<std::string, std::string> > Header; 47 typedef std::list< std::pair<std::string, std::string> > Header;
47
48 void SendHeaderInternal(HttpStatus status);
49 48
50 void PrepareOkHeader(Header& header, 49 void PrepareOkHeader(Header& header,
51 const char* contentType, 50 const char* contentType,
52 bool hasContentLength, 51 bool hasContentLength,
53 uint64_t contentLength, 52 uint64_t contentLength,
56 void SendOkHeader(const Header& header); 55 void SendOkHeader(const Header& header);
57 56
58 void PrepareCookies(Header& header, 57 void PrepareCookies(Header& header,
59 const HttpHandler::Arguments& cookies); 58 const HttpHandler::Arguments& cookies);
60 59
60 HttpOutputStream& stream_;
61
61 public: 62 public:
62 virtual ~HttpOutput() 63 HttpOutput(HttpOutputStream& stream) : stream_(stream)
63 { 64 {
64 } 65 }
65
66 virtual void Send(const void* buffer, size_t length) = 0;
67 66
68 void SendOkHeader(const char* contentType, 67 void SendOkHeader(const char* contentType,
69 bool hasContentLength, 68 bool hasContentLength,
70 uint64_t contentLength, 69 uint64_t contentLength,
71 const char* contentFilename); 70 const char* contentFilename);
72 71
73 void SendString(const std::string& s); 72 void SendBodyData(const void* buffer, size_t length)
73 {
74 stream_.SendBodyData(buffer, length);
75 }
76
77 void SendBodyString(const std::string& str)
78 {
79 stream_.SendBodyString(str);
80 }
74 81
75 void SendMethodNotAllowedError(const std::string& allowed); 82 void SendMethodNotAllowedError(const std::string& allowed);
76 83
77 void SendHeader(HttpStatus status); 84 void SendHeader(HttpStatus status);
78 85
79 void Redirect(const std::string& path); 86 void Redirect(const std::string& path);
87
88 void SendUnauthorized(const std::string& realm);
80 89
81 // Higher-level constructs to send entire buffers ---------------------------- 90 // Higher-level constructs to send entire buffers ----------------------------
82 91
83 void AnswerBufferWithContentType(const std::string& buffer, 92 void AnswerBufferWithContentType(const std::string& buffer,
84 const std::string& contentType); 93 const std::string& contentType);