10 #ifndef __PION_HTTPREQUEST_HEADER__
11 #define __PION_HTTPREQUEST_HEADER__
13 #include <boost/shared_ptr.hpp>
14 #include <pion/PionConfig.hpp>
15 #include <pion/net/HTTPMessage.hpp>
16 #include <pion/net/PionUser.hpp>
36 : m_method(REQUEST_METHOD_GET), m_resource(resource) {}
49 m_original_resource.erase();
50 m_query_string.erase();
51 m_query_params.clear();
52 m_user_record.reset();
59 inline const std::string&
getMethod(
void)
const {
return m_method; }
62 inline const std::string&
getResource(
void)
const {
return m_resource; }
68 inline const std::string&
getQueryString(
void)
const {
return m_query_string; }
71 inline const std::string&
getQuery(
const std::string& key)
const {
72 return getValue(m_query_params, key);
77 return m_query_params;
81 inline bool hasQuery(
const std::string& key)
const {
82 return(m_query_params.find(key) != m_query_params.end());
93 m_resource = m_original_resource = str;
102 m_query_string = str;
107 inline void addQuery(
const std::string& key,
const std::string& value) {
108 m_query_params.insert(std::make_pair(key, value));
112 inline void changeQuery(
const std::string& key,
const std::string& value) {
131 if (! post_content.empty())
132 memcpy(ptr, post_content.c_str(), post_content.size());
142 memcpy(ptr, value.c_str(), value.size());
146 inline void setUser(PionUserPtr user) { m_user_record = user; }
149 inline PionUserPtr
getUser()
const {
return m_user_record; }
161 if (! m_query_string.empty()) {
175 std::string m_method;
178 std::string m_resource;
181 std::string m_original_resource;
184 std::string m_query_string;
190 PionUserPtr m_user_record;
195 typedef boost::shared_ptr<HTTPRequest> HTTPRequestPtr;
void changeQuery(const std::string &key, const std::string &value)
changes the value of a query key
QueryParams & getQueryParams(void)
returns the query parameters
void addQuery(const std::string &key, const std::string &value)
adds a value for the query key
virtual void clear(void)
clears all message data
static void changeValue(DictionaryType &dict, const std::string &key, const std::string &value)
static void deleteValue(DictionaryType &dict, const std::string &key)
const std::string & getResource(void) const
returns the resource uri-stem to be delivered (possibly the result of a redirect) ...
void useQueryParamsForQueryString(void)
use the query parameters to build a query string for the request
HTTPRequest(void)
constructs a new HTTPRequest object (default constructor)
static std::string make_query_string(const QueryParams &query_params)
builds an HTTP query string from a collection of query parameters
void changeResource(const std::string &str)
changes the resource or uri-stem to be delivered (called as the result of a redirect) ...
bool hasQuery(const std::string &key) const
returns true if at least one value for the query key is defined
virtual void clear(void)
clears all request data
void setResource(const std::string &str)
sets the resource or uri-stem originally requested
const std::string & getQuery(const std::string &key) const
returns a value for the query key if any are defined; otherwise, an empty string
void useQueryParamsForPostContent(void)
use the query parameters to build POST content for the request
StringDictionary QueryParams
data type for HTTP query parameters
virtual void updateFirstLine(void) const
updates the string containing the first line for the HTTP message
char * createContentBuffer(void)
const std::string & getOriginalResource(void) const
returns the resource uri-stem originally requested
void setContentLength(const std::size_t n)
sets the length of the payload content (in bytes)
HTTPRequest(const std::string &resource)
void setUser(PionUserPtr user)
sets the user record for HTTP request after authentication
const std::string & getMethod(void) const
returns the request method (i.e. GET, POST, PUT)
void deleteQuery(const std::string &key)
removes all values for a query key
virtual bool isContentLengthImplied(void) const
the content length of the message can never be implied for requests
the following enables use of the lock-free cache
const std::string & getQueryString(void) const
returns the uri-query or query string requested
static const std::string & getValue(const DictionaryType &dict, const std::string &key)
void setContentType(const std::string &type)
sets the content type for the message payload
void setContent(const std::string &value)
add content (for POST) from string
std::string getVersionString(void) const
returns a string representation of the HTTP version (i.e. "HTTP/1.1")
PionUserPtr getUser() const
get the user record for HTTP request after authentication
virtual ~HTTPRequest()
virtual destructor
void clearFirstLine(void) const
void setQueryString(const std::string &str)
sets the uri-query or query string requested
void setMethod(const std::string &str)
sets the HTTP request method (i.e. GET, POST, PUT)