diff options
author | Chris Wilson <chris+github@qwirx.com> | 2015-07-31 06:40:09 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2015-07-31 06:40:09 +0000 |
commit | d72425de59db7d94dd51cca7988c3d025426925b (patch) | |
tree | 2545bc5321aedcfd962422277697e39f1f552ecc | |
parent | 762af2a462607258817fde3dc919ee7db5d1bcf0 (diff) |
Add utility methods to HTTPRequest and HTTPResponse classes.
Allow getting method name of an HTTPRequest, and connection open/closed
status of an HTTPResponse.
-rw-r--r-- | lib/httpserver/HTTPRequest.cpp | 26 | ||||
-rw-r--r-- | lib/httpserver/HTTPRequest.h | 1 | ||||
-rw-r--r-- | lib/httpserver/HTTPResponse.h | 3 |
3 files changed, 29 insertions, 1 deletions
diff --git a/lib/httpserver/HTTPRequest.cpp b/lib/httpserver/HTTPRequest.cpp index 4c5dc149..106bc30a 100644 --- a/lib/httpserver/HTTPRequest.cpp +++ b/lib/httpserver/HTTPRequest.cpp @@ -94,6 +94,32 @@ HTTPRequest::~HTTPRequest() } } +// -------------------------------------------------------------------------- +// +// Function +// Name: HTTPRequest::GetMethodName() +// Purpose: Returns the name of the request's HTTP method verb +// as a string. +// Created: 28/7/15 +// +// -------------------------------------------------------------------------- + +std::string HTTPRequest::GetMethodName() const +{ + switch(mMethod) + { + case Method_UNINITIALISED: return "uninitialised"; + case Method_UNKNOWN: return "unknown"; + case Method_GET: return "GET"; + case Method_HEAD: return "HEAD"; + case Method_POST: return "POST"; + case Method_PUT: return "PUT"; + default: + std::ostringstream oss; + oss << "unknown-" << mMethod; + return oss.str(); + }; +} // -------------------------------------------------------------------------- // diff --git a/lib/httpserver/HTTPRequest.h b/lib/httpserver/HTTPRequest.h index 25effb70..80699e3b 100644 --- a/lib/httpserver/HTTPRequest.h +++ b/lib/httpserver/HTTPRequest.h @@ -77,6 +77,7 @@ public: // // -------------------------------------------------------------------------- enum Method GetMethod() const {return mMethod;} + std::string GetMethodName() const; const std::string &GetRequestURI() const {return mRequestURI;} // Note: the HTTPRequest generates and parses the Host: header diff --git a/lib/httpserver/HTTPResponse.h b/lib/httpserver/HTTPResponse.h index 04051958..978fa91e 100644 --- a/lib/httpserver/HTTPResponse.h +++ b/lib/httpserver/HTTPResponse.h @@ -63,7 +63,7 @@ public: typedef std::pair<std::string, std::string> Header; void SetResponseCode(int Code); - int GetResponseCode() { return mResponseCode; } + int GetResponseCode() const { return mResponseCode; } void SetContentType(const char *ContentType); const std::string& GetContentType() { return mContentType; } @@ -107,6 +107,7 @@ public: void SetResponseIsDynamicContent(bool IsDynamic) {mResponseIsDynamicContent = IsDynamic;} // Set keep alive control, default is to mark as to be closed void SetKeepAlive(bool KeepAlive) {mKeepAlive = KeepAlive;} + bool IsKeepAlive() {return mKeepAlive;} void SetCookie(const char *Name, const char *Value, const char *Path = "/", int ExpiresAt = 0); |