A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Revision:
126:62edacc9f14d
Parent:
117:a725e5ad4fad
Child:
129:9c57197fb698
--- a/tcp/http/http.c	Fri Feb 22 11:26:55 2019 +0000
+++ b/tcp/http/http.c	Mon Feb 25 20:59:19 2019 +0000
@@ -10,10 +10,13 @@
 
 bool HttpTrace = false;
 
-void (*HttpReplyFunction  )(int todo);                                       //Plumb into this from your html server
-int  (*HttpRequestFunction)(char *pPath, char *pLastModified, char *pQuery); //Plumb into this from your html server
+//Plumb into these from your html server
+int  (*HttpRequestFunction)(char *pPath, char *pLastModified);
+void (*HttpGetFunction    )(int todo, char *pQuery);
+bool (*HttpPostFunction   )(int todo, int contentLength, int contentStart, int size, char* pRequestStream, uint32_t positionInRequestStream);
+void (*HttpReplyFunction  )(int todo);
 
-void HttpHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, int* pToDo)
+void HttpHandleRequest(int size, char* pRequestStream, uint32_t positionInRequestStream, int* pToDo, bool* pPostComplete)
 {
     int lastFaultPoint = FaultPoint;
     FaultPoint = FAULT_POINT_HttpHandleRequest;
@@ -23,17 +26,32 @@
         LogF("HTTP  <<< %d (%u)\r\n", size, positionInRequestStream);
     }
     //Handle request for the first packet of data received but leave todo the same after that.
+    int contentLength = 0;
+    int contentStart  = 0;
     if (size && positionInRequestStream == 0)
     {
+        //Read the headers
         char* pMethod;
         char* pPath;
         char* pQuery;
         char* pLastModified;
         FaultPoint = FAULT_POINT_HttpReadRequest;
-        HttpRequestRead(pRequestStream, size, &pMethod, &pPath, &pQuery, &pLastModified);
+        contentStart = HttpRequestRead(pRequestStream, size, &pMethod, &pPath, &pQuery, &pLastModified, &contentLength);
+        
+        //Ask the http server what to do
         FaultPoint = FAULT_POINT_HttpRequestFunction;
-        *pToDo = HttpRequestFunction(pPath, pLastModified, pQuery);
+        *pToDo = HttpRequestFunction(pPath, pLastModified);
+        
+        //Handle the query
+        FaultPoint = FAULT_POINT_HttpGetFunction;
+        HttpGetFunction(*pToDo, pQuery);
     }
+    
+    //Do the upload of anything that needs it
+    FaultPoint = FAULT_POINT_HttpPostFunction;
+    if (!*pPostComplete) *pPostComplete = HttpPostFunction(*pToDo, contentLength, contentStart, size, pRequestStream, positionInRequestStream);
+    
+    //Tidy up
     FaultPoint = lastFaultPoint;
 }
 void HttpSendReply(int* pSize, char* pReplyStream, uint32_t positionInReplyStream, uint16_t mss, int todo)