Single instance HTTP Server using new Ethernet Interface with bug fix for URL arguments

Fork of HTTPServer by Henry Leinen

Files at this revision

API Documentation at this revision

Comitter:
leihen
Date:
Sat Jun 01 17:47:45 2013 +0000
Parent:
6:fe661fa9d18a
Child:
8:ccbdf6e28655
Child:
9:c2a1462b9b71
Commit message:
Fixed a Problem with incorrect HttpBody size when returning GET Request data.
; Fixed incorrect variable size for returned data, which led to a Problem when returned data length exceeds 65535 Bytes.

Changed in this revision

HTTPRequestHandler.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPRequestHandler.h Show annotated file Show diff for this revision Revisions of this file
Handler/FsHandler.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPRequestHandler.cpp	Sat Jun 01 16:49:17 2013 +0000
+++ b/HTTPRequestHandler.cpp	Sat Jun 01 17:47:45 2013 +0000
@@ -86,13 +86,13 @@
 }
 
 
-void HTTPRequestHandler::startResponse(int returnCode, int nLen, HTTPHeaders* header)
+void HTTPRequestHandler::startResponse(int returnCode, long nLen, HTTPHeaders* header)
 {
-    INFO("Starting response !");
+    INFO("Starting response (%ld bytes in total)!", nLen);
     tcp.set_blocking(true, 1500);
     sprintf(buffer, "HTTP/1.1 %d OK\r\n", returnCode);
     tcp.send(buffer, strlen(buffer));
-    sprintf(buffer, "Content-Length: %d\r\n", nLen + 2);    //  Add 2 chars for the terminating CR+LF
+    sprintf(buffer, "Content-Length: %ld\r\n", nLen);    //  Add 2 chars for the terminating CR+LF
     tcp.send(buffer, strlen(buffer));
     if (header == NULL) {
         sprintf(buffer, "Content-Type: text/html\r\nServer: mbed embedded\r\n\r\n");
@@ -112,7 +112,7 @@
 
 void HTTPRequestHandler::processResponse(int nLen, char* body)
 {
-    INFO("Processing Response !");
+    INFO("Processing Response (%d bytes)!\n",nLen);
     tcp.send(body, nLen);
 }
 
--- a/HTTPRequestHandler.h	Sat Jun 01 16:49:17 2013 +0000
+++ b/HTTPRequestHandler.h	Sat Jun 01 17:47:45 2013 +0000
@@ -116,7 +116,7 @@
         * automatically added in \c startResponse. if you need to change the headers, please do NOT 
         * specify the \c Content-Length Header. This is done automatically be the function.
         */
-        void startResponse(int returnCode, int nLen, HTTPHeaders* header = NULL);
+        void startResponse(int returnCode, long nLen, HTTPHeaders* header = NULL);
         void processResponse(int nLen, char* body );
         void endResponse();
 
--- a/Handler/FsHandler.cpp	Sat Jun 01 16:49:17 2013 +0000
+++ b/Handler/FsHandler.cpp	Sat Jun 01 17:47:45 2013 +0000
@@ -16,7 +16,7 @@
 #endif
 
 
-#define MAX_BUFFERSIZE  128
+#define MAX_BUFFERSIZE  512
 static char buffer[MAX_BUFFERSIZE];
 
 
@@ -73,6 +73,8 @@
         startResponse(200, size);
         while(!feof(fp) && !ferror(fp)) {
             int cnt = fread(buffer, 1, MAX_BUFFERSIZE , fp);
+            if (cnt < 0)
+                cnt = 0;
             processResponse(cnt, buffer);
         }
         endResponse();