A HTTP Client for the mbed networking libraries with HTTPFile for use with latest networking stack

Fork of HTTPClient by Donatien Garnier

An extension of the HTTPClient that adds HTTPFile. Currently on get is support and only works when getting binary files.

HTTPFile data("/local/firm.bin");
HTTPResult r = client.get("https://217.140.101.20/media/uploads/ollie8/firm.bin", &data);
if (r == HTTP_OK) {
                            
}
Revision:
14:2744e0c0e527
Parent:
13:be61104f4e91
Child:
15:5ad07f90e895
--- a/HTTPClient.cpp	Sun Aug 05 16:12:10 2012 +0000
+++ b/HTTPClient.cpp	Tue Aug 28 15:55:32 2012 +0000
@@ -355,34 +355,44 @@
     if( recvChunked )
     {
       //Read chunk header
-      crlfPos=0;
-      for(crlfPos++; crlfPos < trfLen - 2; crlfPos++)
+      bool foundCrlf;
+      do
       {
-        if( buf[crlfPos] == '\r' && buf[crlfPos + 1] == '\n' )
-        {
-          break;
-        }
-      }
-      if(crlfPos >= trfLen - 2) //Try to read more
-      {
-        if( trfLen < CHUNK_SIZE )
+        foundCrlf = false;
+        crlfPos=0;
+        buf[trfLen]=0;
+        if(trfLen >= 2)
         {
-          size_t newTrfLen;
-          ret = recv(buf + trfLen, 0, CHUNK_SIZE - trfLen - 1, &newTrfLen);
-          trfLen += newTrfLen;
-          CHECK_CONN_ERR(ret);
-          continue;
+          for(; crlfPos < trfLen - 2; crlfPos++)
+          {
+            if( buf[crlfPos] == '\r' && buf[crlfPos + 1] == '\n' )
+            {
+              foundCrlf = true;
+              break;
+            }
+          }
         }
-        else
+        if(!foundCrlf) //Try to read more
         {
-          PRTCL_ERR();
+          if( trfLen < CHUNK_SIZE )
+          {
+            size_t newTrfLen;
+            ret = recv(buf + trfLen, 0, CHUNK_SIZE - trfLen - 1, &newTrfLen);
+            trfLen += newTrfLen;
+            CHECK_CONN_ERR(ret);
+            continue;
+          }
+          else
+          {
+            PRTCL_ERR();
+          }
         }
-      }
+      } while(!foundCrlf);
       buf[crlfPos] = '\0';
       int n = sscanf(buf, "%x", &readLen);
       if(n!=1)
       {
-        ERR("Could not read chunk length");
+        ERR("Could not read chunk length -- crlfpos == %d & got %s", crlfPos, buf);
         PRTCL_ERR();
       }
 
@@ -429,7 +439,7 @@
       {
         size_t newTrfLen;
         //Read missing chars to find end of chunk
-        ret = recv(buf, 2 - trfLen, CHUNK_SIZE, &newTrfLen);
+        ret = recv(buf + trfLen, 2 - trfLen, CHUNK_SIZE - trfLen - 1, &newTrfLen);
         CHECK_CONN_ERR(ret);
         trfLen += newTrfLen;
       }