A simple web server that can be bound to either the EthernetInterface or the WiflyInterface.
Dependents: Smart-WiFly-WebServer WattEye X10Svr SSDP_Server
Diff: SW_HTTPServer.h
- Revision:
- 27:90a1f5a5392f
- Parent:
- 24:062431453abb
- Child:
- 28:f93ef41b78e1
diff -r 38102ef2b132 -r 90a1f5a5392f SW_HTTPServer.h --- a/SW_HTTPServer.h Thu Oct 10 18:46:55 2013 +0000 +++ b/SW_HTTPServer.h Thu Oct 10 20:38:12 2013 +0000 @@ -51,7 +51,7 @@ /// or signaling outputs. /// /// @code -/// HTTPServer svr(&wifly, HTTP_SERVER_PORT, "/local/", 15, 30, 10, &pc); +/// HTTPServer svr(&wifly, HTTP_SERVER_PORT, "/local", 15, 30, 10, &pc); /// svr.RegisterHandler("/dyn1", SimpleDynamicPage); /// while (true) /// { @@ -187,7 +187,7 @@ */ typedef enum CALLBACKTYPE { CONTENT_LENGTH_REQUEST, ///< ask the client if they wish to accept the data, typically from a POST event - DATA_TRANSFER, ///< not currently used, may allow "chunking" the data to the client + DATA_TRANSFER, ///< used when submitting a file via a form SEND_PAGE, ///< the activated method should now send the page } CallBackType; @@ -195,14 +195,23 @@ * This is the prototype for custom handlers that are activated via a callback * * This callback gets overloaded for a few purposes, which can be identified by the \see CallBackType parameter + * @li CONTENT_LENGTH_REQUEST - the server is asking the callback if it wants to receive the message, + * which may require significant memory. If the request is accepted, true should be returned. + * If the request is denied, false should be returned. + * @li DATA_TRANSFER - the server is handing off a large body of data, which was accepted based + * on the CONTENT_LENGTH_REQUEST callback. The data is now available for processing. + * The callback should return true to continue the processing. * @li SEND_PAGE - the callback should now send the html page, using as many svr->send() as needed. * When the callback returns, it should always indicate true. - * @li CONTENT_LENGTH_REQUEST - the server is asking the callback if it wants to receive the message, - * which may require significant memory. If the request is accepted, true should be returned. - * If the request is denied, false should be returned. + * + * @note The queryParams pointer purpose depends on the callback type. + * For CONTENT_LENGTH_REQUEST, the pointer points to the name=value pairs from the + * header. + * For DATA_TRANSFER, the pointer points to the start of the actual data. + * For SEND_PAGE, * * @param svr is a handle to this class, so the callback has access to member functions - * @param queryParams is a pointer to an array of name value pairs + * @param queryParams is a pointer based on the callback type. * @queryParamCount is the number of parameters. * @return true if command was accepted */ @@ -213,7 +222,8 @@ * * @param wifly is the serial port with the wifly interface. * @param port is the optional parameter for the port number to use, default is 80. - * @param webroot is a file system path to the root folder for the web space. + * @param webroot is a file system path to the root folder for the web space. If any trailing '/' + * is included (e.g. "/web/path/") it will be removed (to "/web/path"). * @param maxheaderParams defines the maximum number of parameters to extract from a header (Host: 192..\r\nConnection: keep-alive\r\n...) * @param maxqueryParams defines the maximum number of query parameters to a dynamic function (and the memory to support them). * @param maxdynamicpages defines the maximum number of dynamic pages that can be registered. @@ -231,13 +241,18 @@ ~HTTPServer(); /** - * Get the webroot. + * Get the path to the webroot, for applications that need to + * reference the file system relative to that point. * - * @returns pointer to the webroot. + * @note The returned value may not be exactly as set at instantiation + * as trailing '/' were removed (unless the web root == "/"). + * e.g. "/msc/web/" becomes "/msc/web" + * + * @returns pointer to the webroot string. */ const char * GetWebRoot() { - return webroot; - } + return (const char *)webroot; + }; /** * The process to call whenever there is free time, as this basically does