Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.h Fri Jun 20 13:30:53 2014 +0200 +++ b/Core/HttpServer/HttpOutput.h Fri Jun 20 13:38:19 2014 +0200 @@ -36,7 +36,7 @@ #include <string> #include <stdint.h> #include "../Enumerations.h" -#include "HttpOutputStream.h" +#include "IHttpOutputStream.h" #include "HttpHandler.h" namespace Orthanc @@ -46,6 +46,38 @@ private: typedef std::list< std::pair<std::string, std::string> > Header; + class StateMachine : public boost::noncopyable + { + protected: + enum State + { + State_WaitingHttpStatus, + State_WritingHeader, + State_WritingBody + }; + + private: + IHttpOutputStream& stream_; + State state_; + + public: + HttpStateMachine(IHttpOutputStream& stream) : + stream_(stream) + state_(State_WaitingHttpStatus) + { + } + + void SendHttpStatus(HttpStatus status); + + void SendHeaderData(const void* buffer, size_t length); + + void SendHeaderString(const std::string& str); + + void SendBodyData(const void* buffer, size_t length); + + void SendBodyString(const std::string& str); + }; + void PrepareOkHeader(Header& header, const char* contentType, bool hasContentLength, @@ -57,10 +89,10 @@ void PrepareCookies(Header& header, const HttpHandler::Arguments& cookies); - HttpOutputStream& stream_; + StateMachine stateMachine_; public: - HttpOutput(HttpOutputStream& stream) : stream_(stream) + HttpOutput(IHttpOutputStream& stream) : stateMachine_(stream) { }