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.cpp
- Revision:
- 24:062431453abb
- Parent:
- 21:660143f20b04
- Child:
- 25:f7d6df7a700a
--- a/SW_HTTPServer.cpp Thu Sep 26 23:47:50 2013 +0000 +++ b/SW_HTTPServer.cpp Thu Oct 10 18:29:12 2013 +0000 @@ -14,7 +14,7 @@ #include "SW_HTTPServer.h" #include "Utility.h" -//#define DEBUG +#define DEBUG const char * DEFAULT_FILENAME = "index.htm"; @@ -457,13 +457,17 @@ char * HTTPServer::rewritePrependWebroot(char * queryString) { - char * temp = (char *)mymalloc(strlen(webroot) + strlen(queryString) + 1); + char * temp = (char *)mymalloc(strlen(webroot) + strlen(queryString) + 2); // save room for '/' if (temp) { + char *lastC; *temp = '\0'; strcpy(temp, webroot); - if (temp[strlen(temp)-1] == '/' && *queryString == '/') - temp[strlen(temp)-1] = '\0'; + lastC = &temp[strlen(temp)-1]; + if (*lastC == '/' && *queryString == '/') + queryString++; // don't create two '/' + else if (*lastC != '/' && *queryString != '/') + strcat(temp, "/"); strcat(temp, queryString); myfree(queryString); return temp; @@ -758,3 +762,4 @@ return res; } #endif +