Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SW_HTTPServer by
Diff: SW_HTTPServer.h
- Revision:
- 13:8975d7928678
- Parent:
- 12:109bf1558300
- Child:
- 14:19c5f6151319
--- a/SW_HTTPServer.h Sun Aug 11 15:49:51 2013 +0000 +++ b/SW_HTTPServer.h Mon Aug 12 11:26:59 2013 +0000 @@ -44,7 +44,7 @@ /// or signaling outputs. /// /// @code -/// HTTPServer svr(&wifly, HTTP_SERVER_PORT, "/local/", 30, 10, &pc); +/// HTTPServer svr(&wifly, HTTP_SERVER_PORT, "/local/", 15, 30, 10, &pc); /// svr.RegisterHandler("/dyn1", SimpleDynamicPage); /// while (true) /// { @@ -134,7 +134,9 @@ * and therefore the needed operation to be performed. * * @code - * bool SimpleDynamicPage(HTTPServer *svr, HTTPServer::CallBackType type, const char * path, const HTTPServer::namevalue *params, int paramcount) { + * bool SimpleDynamicPage(HTTPServer *svr, HTTPServer::CallBackType type, + * const char * path, const HTTPServer::namevalue *queryParams, + * int queryParamCount) { * char buf[100]; * bool ret = false; * @@ -145,10 +147,10 @@ * svr->send("<body>\r\n"); * svr->send("This page was generated dynamically. Create your own name=value pairs on the URL " * "which uses the GET method.<br/>\r\n"); - * sprintf(buf, "%d parameters passed to {%s}:<br/>\r\n", paramcount, path); + * sprintf(buf, "%d parameters passed to {%s}:<br/>\r\n", queryParamCount, path); * svr->send(buf); - * for (int i=0; i<paramcount; i++) { - * sprintf(buf, "%d: %s = %s<br/>\r\n", i, params[i].name, params[i].value); + * for (int i=0; i<queryParamCount; i++) { + * sprintf(buf, "%d: %s = %s<br/>\r\n", i, queryParams[i].name, queryParams[i].value); * svr->send(buf); * } * svr->send("<br/><a href='/'>back to main</a></body></html>\r\n"); @@ -185,11 +187,11 @@ * If the request is denied, false should be returned. * * @param svr is a handle to this class, so the callback has access to member functions - * @param params is a pointer to an array of name value pairs - * @paramcount is the number of parameters. + * @param queryParams is a pointer to an array of name value pairs + * @queryParamCount is the number of parameters. * @return true if command was accepted */ - typedef bool (* Handler)(HTTPServer * svr, CallBackType type, const char *path, const namevalue *params, int paramcount); + typedef bool (* Handler)(HTTPServer * svr, CallBackType type, const char *path, const namevalue *queryParams, int queryParamCount); /** * Create the HTTPServer object. @@ -197,14 +199,15 @@ * @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 maxparams defines the maximum number of parameters to a dynamic function (and the memory to support them). + * @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. * @param pc is the serial port for debug information (I should transform this to a log interface) * @param allocforheader is the memory allocation to support the largest expected header from a client * @param allocforfile is the memory allocation to support sending a file to the client. This is typically sized to fit * an ethernet frame. */ - HTTPServer(Wifly * wifly, int port = 80, const char * webroot = "/", int maxparams = 30, int maxdynamicpages = 10, + HTTPServer(Wifly * wifly, int port = 80, const char * webroot = "/", int maxheaderParams = 15, int maxqueryParams = 30, int maxdynamicpages = 10, PC * pc = NULL, int _allocforheader = MAX_HEADER_SIZE, int _allocforfile = FILESEND_BUF_SIZE); /** @@ -272,7 +275,7 @@ * svr.RegisterHandler("/dyn1", SimpleDynamicPage);svr.RegisterHandler("/dyn1", SimpleDynamicPage); * ... * - * bool SimpleDynamicPage(HTTPServer *svr, HTTPServer::CallBackType type, const char * path, const HTTPServer::namevalue *params, int paramcount) { + * bool SimpleDynamicPage(HTTPServer *svr, HTTPServer::CallBackType type, const char * path, const HTTPServer::namevalue *queryParams, int queryParamCount) { * char buf[100]; * bool ret = false; * @@ -283,10 +286,10 @@ * svr->send("<body>\r\n"); * svr->send("This page was generated dynamically. Create your own name=value pairs on the URL " * "which uses the GET method.<br/>\r\n"); - * sprintf(buf, "%d parameters passed to {%s}:<br/>\r\n", paramcount, path); + * sprintf(buf, "%d parameters passed to {%s}:<br/>\r\n", queryParamCount, path); * svr->send(buf); - * for (int i=0; i<paramcount; i++) { - * sprintf(buf, "%d: %s = %s<br/>\r\n", i, params[i].name, params[i].value); + * for (int i=0; i<queryParamCount; i++) { + * sprintf(buf, "%d: %s = %s<br/>\r\n", i, queryParams[i].name, queryParams[i].value); * svr->send(buf); * } * svr->send("Stats:<br/>\r\n"); @@ -427,6 +430,15 @@ */ int GetMaxHeaderSize(); + /** + * Get a header value, if it exists. + * + * @param hdr is the string to search for (e.g. "Content-Length") + * + * @returns pointer to the value associated with that header. + * @returns NULL if the header is not found. + */ + const char * GetHeaderValue(const char * hdr); /** * Performance parameter @@ -468,7 +480,7 @@ * interact with it. * * @code - * HTTPServer svr(&wifly, HTTP_SERVER_PORT, "/local/", 30, 10, &pc); + * HTTPServer svr(&wifly, HTTP_SERVER_PORT, "/local/", 15, 30, 10, &pc); * ... * svr->GetWifly()->getWiflyVerString() * @endcode @@ -487,9 +499,15 @@ TCPSocketConnection client; char * rewriteWithDefaultFile(char * queryString); char * rewritePrependWebroot(char * queryString); - int maxparams; - namevalue *params; - int paramcount; + + namevalue *queryParams; // Query Parameters from the URL this=that&sky=blue&... + int maxqueryParams; + int queryParamCount; + + namevalue *headerParams; // Header params Host: 192.168...\r\nConnection: keep-alive\r\n... + int maxheaderParams; + int headerParamCount; + int maxheaderbytes; char * headerbuffer; int headerbuffersize; @@ -520,10 +538,10 @@ char * queryType; char * queryString; - char * hostString; - char * contentLength; - char * contentType; - char * authorization; +// char * hostString; +// char * contentLength; +// char * contentType; +// char * authorization; char * postQueryString; /**