comparison Core/HttpServer/HttpOutput.h @ 910:28a52982196e plugins

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 20 Jun 2014 13:38:19 +0200
parents e078ea944089
children 306afd58a0b3
comparison
equal deleted inserted replaced
909:ef71057d8b26 910:28a52982196e
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 "IHttpOutputStream.h"
40 #include "HttpHandler.h" 40 #include "HttpHandler.h"
41 41
42 namespace Orthanc 42 namespace Orthanc
43 { 43 {
44 class HttpOutput 44 class HttpOutput
45 { 45 {
46 private: 46 private:
47 typedef std::list< std::pair<std::string, std::string> > Header; 47 typedef std::list< std::pair<std::string, std::string> > Header;
48
49 class StateMachine : public boost::noncopyable
50 {
51 protected:
52 enum State
53 {
54 State_WaitingHttpStatus,
55 State_WritingHeader,
56 State_WritingBody
57 };
58
59 private:
60 IHttpOutputStream& stream_;
61 State state_;
62
63 public:
64 HttpStateMachine(IHttpOutputStream& stream) :
65 stream_(stream)
66 state_(State_WaitingHttpStatus)
67 {
68 }
69
70 void SendHttpStatus(HttpStatus status);
71
72 void SendHeaderData(const void* buffer, size_t length);
73
74 void SendHeaderString(const std::string& str);
75
76 void SendBodyData(const void* buffer, size_t length);
77
78 void SendBodyString(const std::string& str);
79 };
48 80
49 void PrepareOkHeader(Header& header, 81 void PrepareOkHeader(Header& header,
50 const char* contentType, 82 const char* contentType,
51 bool hasContentLength, 83 bool hasContentLength,
52 uint64_t contentLength, 84 uint64_t contentLength,
55 void SendOkHeader(const Header& header); 87 void SendOkHeader(const Header& header);
56 88
57 void PrepareCookies(Header& header, 89 void PrepareCookies(Header& header,
58 const HttpHandler::Arguments& cookies); 90 const HttpHandler::Arguments& cookies);
59 91
60 HttpOutputStream& stream_; 92 StateMachine stateMachine_;
61 93
62 public: 94 public:
63 HttpOutput(HttpOutputStream& stream) : stream_(stream) 95 HttpOutput(IHttpOutputStream& stream) : stateMachine_(stream)
64 { 96 {
65 } 97 }
66 98
67 void SendOkHeader(const char* contentType, 99 void SendOkHeader(const char* contentType,
68 bool hasContentLength, 100 bool hasContentLength,