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:
Sun Feb 01 16:50:39 2015 +0000
Parent:
32:7b9919d59194
Child:
34:3556275bebf3
Commit message:
Documentation improvements only, focused on HTTPFile.

Changed in this revision

HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
data/HTTPFile.cpp Show annotated file Show diff for this revision Revisions of this file
data/HTTPFile.h Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.cpp	Sat Oct 11 17:26:04 2014 +0000
+++ b/HTTPClient.cpp	Sun Feb 01 16:50:39 2015 +0000
@@ -18,7 +18,7 @@
  */
 
 //Debug is disabled by default
-//#define DEBUG "HTCL"
+#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__);
@@ -85,11 +85,13 @@
 
 HTTPResult HTTPClient::get(const char* url, IHTTPDataIn* pDataIn, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) //Blocking
 {
+    INFO("url: %s, timeout: %d", url, timeout);
     return connect(url, HTTP_GET, NULL, pDataIn, timeout);
 }
 
 HTTPResult HTTPClient::get(const char* url, char* result, size_t maxResultLen, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) //Blocking
 {
+    INFO("url: %s, timeout: %d", url, timeout);
     HTTPText str(result, maxResultLen);
     return get(url, &str, timeout);
 }
@@ -143,6 +145,7 @@
     m_httpResponseCode = 0; //Invalidate code
     m_timeout = timeout;
 
+    INFO("connect(%s,%d,...,%d)", url, method, timeout);
     pDataIn->writeReset();
     if( pDataOut ) {
         pDataOut->readReset();
--- a/data/HTTPFile.cpp	Sat Oct 11 17:26:04 2014 +0000
+++ b/data/HTTPFile.cpp	Sun Feb 01 16:50:39 2015 +0000
@@ -1,6 +1,6 @@
 #include "HTTPFile.h"
 
-//#define DEBUG "HTfi"
+#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__);
--- a/data/HTTPFile.h	Sat Oct 11 17:26:04 2014 +0000
+++ b/data/HTTPFile.h	Sun Feb 01 16:50:39 2015 +0000
@@ -1,13 +1,25 @@
 #ifndef HTTPFILE_H
 #define HTTPFILE_H
-#if 1
 #include <mbed.h>
 #include "../IHTTPData.h"
 
 
+/// A file handling mechanism - downloads files to a locally accessible file system
 class HTTPFile : public IHTTPDataIn {
     
     public:
+        /// Instantiate HTTPFile with a specified file on a locally accessible file system.
+        ///
+        /// @code
+        /// HTTPFile latest("/local/status.txt");
+        /// HTTPErrorCode = http.get("http://server.dom/path/serverstatus.txt", &latest);
+        /// if (HTTPErrorCode == HTTP_OK) {
+        ///    ... // file successfully downloaded
+        /// }
+        /// @endcode
+        ///
+        /// @param filename is the fully qualified filename to create.
+        ///
         HTTPFile(char* filename);
         
         /** Closes the file, should be called once the http connection is closed.
@@ -51,5 +63,4 @@
         size_t m_len;
         bool m_chunked;
 };
-#endif
 #endif  // HTTPFILE_H
\ No newline at end of file