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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPFile.h Source File

HTTPFile.h

00001 #ifndef HTTPFILE_H
00002 #define HTTPFILE_H
00003 #include <mbed.h>
00004 #include "../IHTTPData.h"
00005 
00006 
00007 /// A file handling mechanism - downloads files to a locally accessible file system
00008 class HTTPFile : public IHTTPDataIn {
00009     
00010     public:
00011         /// Instantiate HTTPFile with a specified file on a locally accessible file system.
00012         ///
00013         /// @code
00014         /// HTTPFile latest("/local/status.txt");
00015         /// HTTPErrorCode = http.get("http://server.dom/path/serverstatus.txt", &latest);
00016         /// if (HTTPErrorCode == HTTP_OK) {
00017         ///    ... // file successfully downloaded
00018         /// }
00019         /// @endcode
00020         ///
00021         /// @param filename is the fully qualified filename to create.
00022         ///
00023         HTTPFile(char* filename);
00024         
00025         /** Closes the file, should be called once the http connection is closed.
00026          */
00027         void close();
00028         
00029     protected:     
00030        
00031         friend class HTTPClient;
00032     
00033         /** Reset stream to its beginning 
00034         * Called by the HTTPClient on each new request
00035         */
00036         virtual void writeReset();
00037         
00038         /** Write a piece of data transmitted by the server
00039         * @param[in] buf Pointer to the buffer from which to copy the data
00040         * @param[in] len Length of the buffer
00041         * @returns number of bytes written.
00042         */
00043         virtual int write(const char* buf, size_t len);
00044         
00045         /** Set MIME type
00046         * @param[in] type Internet media type from Content-Type header
00047         */
00048         virtual void setDataType(const char* type);
00049         
00050         /** Determine whether the data is chunked
00051         *  Recovered from Transfer-Encoding header
00052         * @param[in] chunked indicates the transfer is chunked.
00053         */
00054         virtual void setIsChunked(bool chunked);
00055         
00056         /** If the data is not chunked, set its size
00057         * From Content-Length header
00058         * @param[in] len defines the size of the non-chunked transfer.
00059         */
00060         virtual void setDataLen(size_t len);
00061     private:
00062         FILE *file;
00063         size_t m_len;
00064         bool m_chunked;
00065 };
00066 #endif  // HTTPFILE_H