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:
35:d9e2d1c96b75
Parent:
34:3556275bebf3
Child:
36:a5c13e512b78
--- a/HTTPClient.cpp	Sun Mar 08 17:50:52 2015 +0000
+++ b/HTTPClient.cpp	Thu Aug 06 11:11:31 2015 +0000
@@ -21,10 +21,10 @@
 //#define DEBUG "HTCL"
 #include <cstdio>
 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
-#define DBG(x, ...)  std::printf("[DBG %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define ERR(x, ...)  std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define DBG(x, ...)  std::printf("[DBG %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WRN %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define ERR(x, ...)  std::printf("[ERR %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define INFO(x, ...) std::printf("[INF %s %3d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
 #else
 #define DBG(x, ...)
 #define WARN(x, ...)
@@ -157,7 +157,7 @@
     char path[MAXLEN_VALUE];
     size_t recvContentLength = 0;
     bool recvChunked = false;
-    int crlfPos = 0;
+    size_t crlfPos = 0;
     char buf[CHUNK_SIZE];
     size_t trfLen;
     int ret = 0;
@@ -549,7 +549,7 @@
     return HTTP_OK;
 }
 
-HTTPResult HTTPClient::send(char* buf, size_t len) //0 on success, err code on failure
+HTTPResult HTTPClient::send(const char* buf, size_t len) //0 on success, err code on failure
 {
     if(len == 0) {
         len = strlen(buf);
@@ -587,7 +587,7 @@
         return HTTP_PARSE; //URL is invalid
     }
 
-    if( maxSchemeLen < hostPtr - schemePtr + 1 ) { //including NULL-terminating char
+    if( (uint16_t)maxSchemeLen < hostPtr - schemePtr + 1 ) { //including NULL-terminating char
         WARN("Scheme str is too small (%d >= %d)", maxSchemeLen, hostPtr - schemePtr + 1);
         return HTTP_PARSE;
     }
@@ -653,7 +653,7 @@
     static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
     unsigned int c, c1, c2, c3;
 
-    if (len < ((((length-1)/3)+1)<<2)) return -1;
+    if ((uint16_t)len < ((((length-1)/3)+1)<<2)) return -1;
     for(unsigned int i = 0, j = 0; i<length; i+=3,j+=4) {
         c1 = ((((unsigned char)*((unsigned char *)&input[i]))));
         c2 = (length>i+1)?((((unsigned char)*((unsigned char *)&input[i+1])))):0;