The lib with which to make LPC1768 a simple HTTP server. This have not yet implemented. fopen() DOESN'T WORK after EthernetInterface::connect() is called as using mbed-os 5.4~. See also https://os.mbed.com/questions/80658/HardFault-occurs-when-fopen-is-called-af/ or https://github.com/ARMmbed/mbed-os/issues/6578 and https://github.com/ARMmbed/mbed-os/issues/6624

Fork of HTTP_SERVER by Akifumi Takahashi

Revision:
16:c3920b5b8572
Parent:
15:9b2cfbaf1c12
Child:
17:ce5845164001
diff -r 9b2cfbaf1c12 -r c3920b5b8572 HTTP_SERVER.cpp
--- a/HTTP_SERVER.cpp	Fri Mar 16 23:17:28 2018 +0000
+++ b/HTTP_SERVER.cpp	Mon Mar 19 09:25:32 2018 +0000
@@ -1,8 +1,8 @@
 #include "HTTP_SERVER.h"
 #include "string"
-#ifndef HTTP_SERVER_DEBUG
+//#ifndef HTTP_SERVER_DEBUG
 #define HTTP_SERVER_DEBUG
-#endif
+//#endif
 /*
 LOG:
 "sys_thread_new number error" is occurred when an instance of this class is instantiated in main() in main.cpp
@@ -25,7 +25,7 @@
 char req_buf[1024] was not uesed anywhere...
 so it was deleted.
 
-bool deep-alive was also not uesed so deleted it.
+bool keep-alive was also not uesed so deleted it.
 
 After doing those above, the error massage was DERAYED but
 it even now occur.
@@ -151,7 +151,7 @@
         while (socket_connection) {
             printf("(HTTP_SERVER) connected\r\n");
 
-            char buffer[256]   = {0};
+            char buffer[1024]   = {0};
             char* httpmethod    = NULL;
             char* filepath      = NULL;
             char* http_ver      = NULL;
@@ -161,7 +161,11 @@
             //
             //  Request Analysis
             //
-            analyzeRequest(buffer, 255, httpmethod, filepath, http_ver);
+            printf("(HTTP_SERVER) Request Analysis\r\n");
+            analyzeRequest(buffer, 1023, httpmethod, filepath, http_ver);
+            DEBUG_PRINT_LINE("httpmethod: %s", httpmethod);
+            DEBUG_PRINT_LINE("file path:  %s", filepath);
+            DEBUG_PRINT_LINE("http ver :  %s", http_ver);
             //
             //  Response
             //
@@ -181,7 +185,7 @@
 
 }
 
-bool HttpServer::analyzeRequest(char* buffer, int buffer_size, char* httpmethod, char* filepath, char* http_ver)
+bool HttpServer::analyzeRequest(char* buffer, int buffer_size, char* &httpmethod, char* &filepath, char* &http_ver)
 {
 
     DEBUG_PRINT_LINE("Request Analysis");
@@ -212,22 +216,20 @@
             httpmethod = strtok(buffer," ");
             filepath = strtok(NULL, " ");
             http_ver = strtok(NULL, "\r\n");
-            DEBUG_PRINT_LINE("httpmethod: %s", httpmethod);
-            DEBUG_PRINT_LINE("file path:  %s", filepath);
-            DEBUG_PRINT_LINE("http ver :  %s", http_ver);
             break;
     }
     return true;
 }
 
-bool HttpServer::sendResponse(char* httpmethod, char*filepath, char* http_ver)
+bool HttpServer::sendResponse(char* httpmethod, char* filepath, char* http_ver)
 {
     if (strcmp(httpmethod,"GET") == 0 ) {
         DEBUG_PRINT_LINE("GET request incomming.");
 
         //  file calibration
         DEBUG_PRINT_LINE("file opening");
-        fhndl.open(filepath,"rb");
+        DEBUG_PRINT_LINE("filepath: %s", filepath);
+        fhndl.open(filepath,"rb");/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         if(fhndl.arrival()) {
             msger.setStatusLine(200, "OK");
             if(msger.setHeaderField("Content-Length", fhndl.getFileSize()))     DEBUG_PRINT_LINE("buffer over flow @ ResponseMessenger");
@@ -278,4 +280,6 @@
         socket_connection = false;
     }
     printf("(HTTP_SERVER) Response to Request has done\r\n");
+    
+    return true;
 }