diff options
author | Chris Wilson <chris+github@qwirx.com> | 2009-01-04 13:56:55 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2009-01-04 13:56:55 +0000 |
commit | 95f5a1c2dff53b88c274e358bd0cd07758819a12 (patch) | |
tree | 66745b869b2a7b039eca307fe3ed3b9074278302 /lib/httpserver/HTTPResponse.h | |
parent | 0d1fc68db7b50c86b6eb3f635399af66ba54bd05 (diff) |
Allow adding headers to an HTTPRequest.
Allow getting response headers out of HTTPResponse.
Rename HTTPRequest Read and Write methods to Send and Receive, to avoid
confusion with IOStream.
Diffstat (limited to 'lib/httpserver/HTTPResponse.h')
-rw-r--r-- | lib/httpserver/HTTPResponse.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/httpserver/HTTPResponse.h b/lib/httpserver/HTTPResponse.h index 58cc3baa..e4d4fd91 100644 --- a/lib/httpserver/HTTPResponse.h +++ b/lib/httpserver/HTTPResponse.h @@ -30,12 +30,14 @@ class HTTPResponse : public CollectInBufferStream public: HTTPResponse(); ~HTTPResponse(); + private: // no copying HTTPResponse(const HTTPResponse &); HTTPResponse &operator=(const HTTPResponse &); -public: + typedef std::pair<std::string, std::string> Header; +public: void SetResponseCode(int Code); int GetResponseCode() { return mResponseCode; } void SetContentType(const char *ContentType); @@ -52,6 +54,29 @@ public: void AddHeader(const char *Header, const char *Value); void AddHeader(const char *Header, const std::string &rValue); void AddHeader(const std::string &rHeader, const std::string &rValue); + bool GetHeader(const std::string& rName, std::string* pValueOut) const + { + for (std::vector<Header>::const_iterator + i = mExtraHeaders.begin(); + i != mExtraHeaders.end(); i++) + { + if (i->first == rName) + { + *pValueOut = i->second; + return true; + } + } + return false; + } + std::string GetHeaderValue(const std::string& rName) + { + std::string value; + if (!GetHeader(rName, &value)) + { + THROW_EXCEPTION(CommonException, ConfigNoKey); + } + return value; + } // Set dynamic content flag, default is content is dynamic void SetResponseIsDynamicContent(bool IsDynamic) {mResponseIsDynamicContent = IsDynamic;} @@ -68,6 +93,7 @@ public: Code_Found = 302, // redirection Code_NotModified = 304, Code_TemporaryRedirect = 307, + Code_MethodNotAllowed = 400, Code_Unauthorized = 401, Code_Forbidden = 403, Code_NotFound = 404, @@ -111,7 +137,6 @@ private: bool mResponseIsDynamicContent; bool mKeepAlive; std::string mContentType; - typedef std::pair<std::string, std::string> Header; std::vector<Header> mExtraHeaders; int mContentLength; // only used when reading response from stream |