#ifndef __HTTPResponse_h__ #define __HTTPResponse_h__ #include "MString.h" #include namespace coreutils { /// /// HTTPResponse builds a raw HTTP/1.1 response (status line + headers + /// body) ready to write to a socket. Output-only, not a Parser - there's /// nothing to resume here, the whole thing is built and serialized in /// one pass once a handler has finished producing its body. /// /// Deliberately new rather than built on/patched from IMFResponse - /// IMFResponse's own header-emission code is dead (calls addHeader()/ /// output(), neither of which exist on that class) and it never grew a /// real headers container, so there's nothing there safe to extend. /// class HTTPResponse { public: HTTPResponse(); void setStatus(int code, ZString text); void setHeader(ZString name, ZString value); void setBody(ZString body); /// /// Serializes the full response - status line, headers (an explicit /// Content-Length header is respected as-is; otherwise one is /// computed from the body automatically), the blank line, and the /// body - ready to write to a socket. /// MString serialize(); private: int statusCode = 200; MString statusText; std::map headers; MString body; }; } #endif