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 Mar 15 18:40:29 2014 +0000
Parent:
22:d6b08d9749d6
Child:
24:eee214e3e806
Commit message:
Added HTTPFile methods

Changed in this revision

HTTPClient.h 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.h	Sun Mar 09 16:39:40 2014 +0000
+++ b/HTTPClient.h	Sat Mar 15 18:40:29 2014 +0000
@@ -179,5 +179,6 @@
 //Including data containers here for more convenience
 #include "data/HTTPText.h"
 #include "data/HTTPMap.h"
+#include "data/HTTPFile.h"
 
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPFile.cpp	Sat Mar 15 18:40:29 2014 +0000
@@ -0,0 +1,40 @@
+#include "HTTPFile.h"
+#if 0
+HTTPFile::HTTPFile(char* filename) {
+    file = fopen(filename, "w");    
+}
+
+void HTTPFile::close() {
+    if (file) {
+        fclose(file);    
+    }        
+}
+
+void HTTPFile::writeReset() {
+    if (file) {
+        rewind(file);   
+    }
+}
+
+int HTTPFile::write(const char* buf, size_t len) {
+    if (file) {
+        len = fwrite(&buf, 1, len, file);    
+        if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !len)) {
+            close();
+        }
+    }
+    return len;    
+}
+
+void HTTPFile::setDataType(const char* type) {
+
+}
+
+void HTTPFile::setIsChunked(bool chunked) {
+    m_chunked = chunked;
+}
+
+void HTTPFile::setDataLen(size_t len) {
+    m_len = len;
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data/HTTPFile.h	Sat Mar 15 18:40:29 2014 +0000
@@ -0,0 +1,52 @@
+#ifndef HTTPFILE_H
+#define HTTPFILE_H
+#if 0
+#include <mbed.h>
+#include "../IHTTPData.h"
+
+
+class HTTPFile : public IHTTPDataIn {
+    
+    public:
+        HTTPFile(char* filename);
+        
+        /** Closes the file, should be called once the http connection is closed.
+         */
+        void close();
+        
+    protected:     
+       
+        friend class HTTPClient;
+    
+        /** Reset stream to its beginning 
+        * Called by the HTTPClient on each new request
+        */
+        virtual void writeReset();
+        
+        /** Write a piece of data transmitted by the server
+        * @param buf Pointer to the buffer from which to copy the data
+        * @param len Length of the buffer
+        */
+        virtual int write(const char* buf, size_t len);
+        
+        /** Set MIME type
+        * @param type Internet media type from Content-Type header
+        */
+        virtual void setDataType(const char* type);
+        
+        /** Determine whether the data is chunked
+        *  Recovered from Transfer-Encoding header
+        */
+        virtual void setIsChunked(bool chunked);
+        
+        /** If the data is not chunked, set its size
+        * From Content-Length header
+        */
+        virtual void setDataLen(size_t len);
+    private:
+        FILE *file;
+        size_t m_len;
+        bool m_chunked;
+};
+#endif
+#endif
\ No newline at end of file