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
20 std::stringstream* headers;
24 /** A socket pointer, which you must return in your HTTPDocument class
25 * if you reply to this request.
29 /** Initialize HTTPRequest.
30 * This constructor is called by m_httpd.so to initialize the class.
31 * @param request_type The request type, e.g. GET, POST, HEAD
32 * @param uri The URI, e.g. /page
33 * @param hdr The headers sent with the request
34 * @param opaque An opaque pointer used internally by m_httpd, which you must pass back to the module in your reply.
35 * @param ip The IP address making the web request.
37 HTTPRequest(const std::string &request_type, const std::string &uri, std::stringstream* hdr, void* opaque, const std::string &ip)
38 : type(request_type), document(uri), ipaddr(ip), headers(hdr), sock(opaque)
43 * All the headers for the web request are returned, as a pointer to a stringstream.
44 * @return The header information
46 std::stringstream* GetHeaders()
51 /** Get the request type.
52 * Any request type can be intercepted, even ones which are invalid in the HTTP/1.1 spec.
53 * @return The request type, e.g. GET, POST, HEAD
55 std::string& GetType()
61 * The URI string (URL minus hostname and scheme) will be provided by this function.
62 * @return The URI being requested
69 /** Get IP address of requester.
70 * The requesting system's ip address will be returned.
71 * @return The IP address as a string
79 /** You must return a HTTPDocument to the httpd module by using the Request class.
80 * When you initialize this class you may initialize it with all components required to
81 * form a valid HTTP response, including document data, headers, and a response code.
83 class HTTPDocument : public classbase
87 std::stringstream* document;
89 std::string extraheaders;
93 /** The socket pointer from an earlier HTTPRequest
97 /** Initialize a HTTPRequest ready for sending to m_httpd.so.
98 * @param opaque The socket pointer you obtained from the HTTPRequest at an earlier time
99 * @param doc A stringstream containing the document body
100 * @param response A valid HTTP/1.0 or HTTP/1.1 response code. The response text will be determined for you
101 * based upon the response code.
102 * @param extra Any extra headers to include with the defaults, seperated by carriage return and linefeed.
104 HTTPDocument(void* opaque, std::stringstream* doc, int response, const std::string &extra) : document(doc), responsecode(response), extraheaders(extra), sock(opaque)
108 /** Get the document text.
109 * @return The document text
111 std::stringstream* GetDocument()
113 return this->document;
116 /** Get the document size.
117 * @return the size of the document text in bytes
119 unsigned long GetDocumentSize()
121 return this->document->str().length();
124 /** Get the response code.
125 * @return The response code
127 int GetResponseCode()
129 return this->responsecode;
133 * @return The header text, headers seperated by carriage return and linefeed.
135 std::string& GetExtraHeaders()
137 return this->extraheaders;