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.

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sat Apr 26 17:24:07 2014 +0000
Parent:
26:58b6fe9f596b
Child:
28:c0c7a6321f84
Commit message:
Debug turned on

Changed in this revision

data/HTTPFile.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/data/HTTPFile.cpp	Sun Apr 20 17:05:27 2014 +0000
+++ b/data/HTTPFile.cpp	Sat Apr 26 17:24:07 2014 +0000
@@ -1,25 +1,48 @@
 #include "HTTPFile.h"
-#if 1
+
+#define DEBUG "HTfi"
+#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__);
+#else
+#define DBG(x, ...)
+#define WARN(x, ...)
+#define ERR(x, ...)
+#define INFO(x, ...)
+#endif
+
 HTTPFile::HTTPFile(char* filename) {
-    file = fopen(filename, "w");    
+    INFO("HTTPFile %s", filename);
+    file = fopen(filename, "w");   
+    m_chunked = false; 
 }
 
 void HTTPFile::close() {
+    INFO("close()");
     if (file) {
-        fclose(file);    
+        fclose(file);
+        file = NULL;
     }        
 }
 
 void HTTPFile::writeReset() {
+    INFO("writeReset()");
     if (file) {
         rewind(file);   
     }
 }
 
 int HTTPFile::write(const char* buf, size_t len) {
+    size_t written;
+    INFO("write(%d,%s) m_len(%d), chunk %d", len, buf, m_len, m_chunked);
     if (file) {
-        len = fwrite(&buf, 1, len, file);    
-        if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !len)) {
+        written = fwrite(&buf, 1, len, file);   
+        INFO("  writ:%d, ftell: %d", written, ftell(file)); 
+        if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !written)) {
+            INFO("closing");
             close();
         }
     }
@@ -27,7 +50,7 @@
 }
 
 void HTTPFile::setDataType(const char* type) {
-
+    INFO("setDataType(%s)", type);
 }
 
 //void HTTPFile::setLocation(const char * location) {
@@ -35,10 +58,11 @@
 //}
 
 void HTTPFile::setIsChunked(bool chunked) {
+    INFO("setIsChunked(%d)", chunked);
     m_chunked = chunked;
 }
 
 void HTTPFile::setDataLen(size_t len) {
+    INFO("setDataLen(%d)", len);
     m_len = len;
 }
-#endif
\ No newline at end of file