From 95f5a1c2dff53b88c274e358bd0cd07758819a12 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sun, 4 Jan 2009 13:56:55 +0000 Subject: 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. --- lib/httpserver/HTTPResponse.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'lib/httpserver/HTTPResponse.h') 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 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
::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 Header; std::vector
mExtraHeaders; int mContentLength; // only used when reading response from stream -- cgit v1.2.3