HTTP Server library for Mbed OS-5. A fork of Henry Leinen's [[https://os.mbed.com/users/leihen/code/HTTPServer/]] library.

Dependents:   STM32F407VET6_HTTPServer

Revision:
17:8bcc62289a07
Parent:
16:cc3f5c53d0d5
--- a/Handler/FsHandler.cpp	Sat Aug 17 16:17:55 2013 +0000
+++ b/Handler/FsHandler.cpp	Sun Oct 06 18:10:41 2019 +0000
@@ -4,7 +4,7 @@
 #define DEBUG
 #include "hl_debug.h"
 
-
+DigitalOut led1(LED1);
 
 static int matchstrings(const char* one, const char* two)
 {
@@ -19,9 +19,10 @@
 
 std::map<const char*, const char*> HTTPFsRequestHandler::m_fsMap;
  
-HTTPFsRequestHandler::HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocketConnection& Tcp)
+HTTPFsRequestHandler::HTTPFsRequestHandler(const char* rootPath, const char* localPath, HTTPConnection::HTTPMessage& Msg, TCPSocket* Tcp)
     : HTTPRequestHandler(Msg, Tcp)
 {
+    INFO("Request handler called.");
     m_rootPath = rootPath;
     m_localPath = localPath;
     
@@ -58,6 +59,7 @@
 int HTTPFsRequestHandler::handleGetRequest()
 {
     HTTPHeaders headers;
+    int retval = 0;   //success
     
     if (m_localPath.length() > 4) 
         getStandardHeaders(headers, m_localPath.substr(m_localPath.length()-4).c_str());
@@ -65,7 +67,7 @@
         getStandardHeaders(headers);
     
     INFO("Handling Get Request (root = %s, local = %s).", m_rootPath.c_str(), m_localPath.c_str());
-    int retval = 0;   //success
+    
     std::string reqPath;
 
     //  Check if we received a directory with the local bath
@@ -79,7 +81,9 @@
     INFO("Mapping \"%s\" to \"%s\"", msg.uri.c_str(), reqPath.c_str());
         
     FILE *fp = fopen(reqPath.c_str(), "r");
+    INFO("fopen(reqPath.c_str()");
     if (fp != NULL) {
+        INFO("fp != NULL");
         char * pBuffer = NULL;
         int sz = 8192;
         while( pBuffer == NULL) {
@@ -90,6 +94,7 @@
         }
         
         //  File was found and can be returned
+        INFO("File was found and can be returned");
     
         //  first determine the size
         fseek(fp, 0, SEEK_END);
@@ -116,11 +121,50 @@
 }
 
 int HTTPFsRequestHandler::handlePostRequest()
-{
-    return 404;
+{  
+    INFO("Handling Post Request (msg.uri = %s).", msg.uri.c_str());
+    
+    if( std::string::npos != msg.uri.find("/toggle") )
+    {
+        led1 = !led1;        
+        return 0;
+    }    
+    else
+    {
+        return 404;
+    }
 }
 
 int HTTPFsRequestHandler::handlePutRequest()
 {
     return 404;
-}
\ No newline at end of file
+}
+
+uint32_t HTTPFsRequestHandler::get_http_param_value(char* param_name)
+{
+    uint8_t * name = 0;
+    uint8_t * pos2;
+    uint16_t len = 0;
+    char value[10];
+    uint32_t ret = 0;
+    
+    //msg.attri
+    if((name = (uint8_t *)strstr(msg.attri, param_name)))
+    {
+        name += strlen(param_name) + 1;
+        pos2 = (uint8_t*)strstr((char*)name, "&");
+        if(!pos2)
+        {
+            pos2 = name + strlen((char*)name);
+        }
+        len = pos2 - name;
+        
+        if(len)
+        {
+            strncpy(value, (char*)name, len);
+            ret = atoi(value);
+        }
+    }
+    return ret;
+}
+