Fixed custom headers and Basic authorization, added support for redirection, functional file download interface can be used for SW updates and more.

Dependents:   Sample_HTTPClient Sample_HTTPClient LWM2M_NanoService_Ethernet LWM2M_NanoService_Ethernet ... more

Fork of HTTPClient by Vincent Wochnik

More recent changes - added iCal processing.

Derivative of a derivative, however this one works when it comes to supplying Basic authorization to access a protected resource. Some additional changes to the debug interface to clean it up for consistency with many other components I have.

Revision:
25:76084defa790
Parent:
24:eee214e3e806
Child:
26:58b6fe9f596b
--- a/HTTPClient.cpp	Sat Mar 15 22:18:30 2014 +0000
+++ b/HTTPClient.cpp	Sun Mar 23 20:40:05 2014 +0000
@@ -46,7 +46,8 @@
 #include "HTTPClient.h"
 
 HTTPClient::HTTPClient() :
-    m_sock(), m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0), 
+    m_sock(), m_basicAuthUser(NULL), m_basicAuthPassword(NULL), 
+    m_nCustomHeaders(0), m_httpResponseCode(0), 
     m_maxredirections(1), m_location(NULL)
 {
 
@@ -200,6 +201,7 @@
         }
 
         // send authorization
+        INFO("send auth (if defined)");
         if (m_basicAuthUser && m_basicAuthPassword) {
             strcpy(buf, "Authorization: Basic ");
             createauth(m_basicAuthUser, m_basicAuthPassword, buf+strlen(buf), sizeof(buf)-strlen(buf));
@@ -215,6 +217,7 @@
         }
 
         //Send all headers
+        INFO("Send custom header(s) %d (if any)", m_nCustomHeaders);
         for (size_t nh = 0; nh < m_nCustomHeaders * 2; nh+=2) {
             INFO("hdr[%d] %s:", nh, m_customHeaders[nh]);
             INFO("        %s", m_customHeaders[nh+1]);
@@ -293,7 +296,8 @@
 
         //Receive response
         DBG("Receiving response");
-        ret = recv(buf, CHUNK_SIZE - 1, CHUNK_SIZE - 1, &trfLen); //Read n bytes
+        //ret = recv(buf, CHUNK_SIZE - 1, CHUNK_SIZE - 1, &trfLen); //Read n bytes
+        ret = recv(buf, 1, CHUNK_SIZE - 1, &trfLen);    // recommended by Rob Noble to avoid timeout wait
         CHECK_CONN_ERR(ret);
         buf[trfLen] = '\0';
         INFO("Received \r\n(%s\r\n)", buf);
@@ -362,7 +366,7 @@
 
             int n = sscanf(buf, "%31[^:]: %63[^\r\n]", key, value);
             if ( n == 2 ) {
-                DBG("Read header : %s: %s\n", key, value);
+                DBG("Read header : %s: %s", key, value);
                 if( !strcmp(key, "Content-Length") ) {
                     sscanf(value, "%d", &recvContentLength);
                     pDataIn->setDataLen(recvContentLength);