9 /** This class represents a HTTP request.
10 * It will be sent to all modules as the data section of
13 class HTTPRequest : public classbase
21 std::stringstream* headers;
25 /** A socket pointer, which you must return in your HTTPDocument class
26 * if you reply to this request.
30 /** Initialize HTTPRequest.
31 * This constructor is called by m_httpd.so to initialize the class.
32 * @param request_type The request type, e.g. GET, POST, HEAD
33 * @param uri The URI, e.g. /page
34 * @param hdr The headers sent with the request
35 * @param opaque An opaque pointer used internally by m_httpd, which you must pass back to the module in your reply.
36 * @param ip The IP address making the web request.
37 * @param pdata The post data (content after headers) received with the request, up to Content-Length in size
39 HTTPRequest(const std::string &request_type, const std::string &uri, std::stringstream* hdr, void* opaque, const std::string &ip, const std::string &pdata)
40 : type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(opaque)
45 * All the headers for the web request are returned, as a pointer to a stringstream.
46 * @return The header information
48 std::stringstream* GetHeaders()
53 /** Get the post data (request content).
54 * All post data will be returned, including carriage returns and linefeeds.
55 * @return The postdata
57 std::string& GetPostData()
62 /** Get the request type.
63 * Any request type can be intercepted, even ones which are invalid in the HTTP/1.1 spec.
64 * @return The request type, e.g. GET, POST, HEAD
66 std::string& GetType()
72 * The URI string (URL minus hostname and scheme) will be provided by this function.
73 * @return The URI being requested
80 /** Get IP address of requester.
81 * The requesting system's ip address will be returned.
82 * @return The IP address as a string
90 /** You must return a HTTPDocument to the httpd module by using the Request class.
91 * When you initialize this class you may initialize it with all components required to
92 * form a valid HTTP response, including document data, headers, and a response code.
94 class HTTPDocument : public classbase
98 std::stringstream* document;
100 std::string extraheaders;
104 /** The socket pointer from an earlier HTTPRequest
108 /** Initialize a HTTPRequest ready for sending to m_httpd.so.
109 * @param opaque The socket pointer you obtained from the HTTPRequest at an earlier time
110 * @param doc A stringstream containing the document body
111 * @param response A valid HTTP/1.0 or HTTP/1.1 response code. The response text will be determined for you
112 * based upon the response code.
113 * @param extra Any extra headers to include with the defaults, seperated by carriage return and linefeed.
115 HTTPDocument(void* opaque, std::stringstream* doc, int response, const std::string &extra) : document(doc), responsecode(response), extraheaders(extra), sock(opaque)
119 /** Get the document text.
120 * @return The document text
122 std::stringstream* GetDocument()
124 return this->document;
127 /** Get the document size.
128 * @return the size of the document text in bytes
130 unsigned long GetDocumentSize()
132 return this->document->str().length();
135 /** Get the response code.
136 * @return The response code
138 int GetResponseCode()
140 return this->responsecode;
144 * @return The header text, headers seperated by carriage return and linefeed.
146 std::string& GetExtraHeaders()
148 return this->extraheaders;