Fork HTTPClient and Modfiy code for mbed 6.0

Dependents:   mbed-demo-http-get-json

Committer:
WiredHome
Date:
Sun Feb 01 16:50:39 2015 +0000
Revision:
33:d4d1475bafc0
Parent:
32:7b9919d59194
Documentation improvements only, focused on HTTPFile.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 23:517fec8b8b99 1 #ifndef HTTPFILE_H
WiredHome 23:517fec8b8b99 2 #define HTTPFILE_H
WiredHome 23:517fec8b8b99 3 #include <mbed.h>
WiredHome 23:517fec8b8b99 4 #include "../IHTTPData.h"
WiredHome 23:517fec8b8b99 5
WiredHome 23:517fec8b8b99 6
WiredHome 33:d4d1475bafc0 7 /// A file handling mechanism - downloads files to a locally accessible file system
WiredHome 23:517fec8b8b99 8 class HTTPFile : public IHTTPDataIn {
WiredHome 23:517fec8b8b99 9
WiredHome 23:517fec8b8b99 10 public:
WiredHome 33:d4d1475bafc0 11 /// Instantiate HTTPFile with a specified file on a locally accessible file system.
WiredHome 33:d4d1475bafc0 12 ///
WiredHome 33:d4d1475bafc0 13 /// @code
WiredHome 33:d4d1475bafc0 14 /// HTTPFile latest("/local/status.txt");
WiredHome 33:d4d1475bafc0 15 /// HTTPErrorCode = http.get("http://server.dom/path/serverstatus.txt", &latest);
WiredHome 33:d4d1475bafc0 16 /// if (HTTPErrorCode == HTTP_OK) {
WiredHome 33:d4d1475bafc0 17 /// ... // file successfully downloaded
WiredHome 33:d4d1475bafc0 18 /// }
WiredHome 33:d4d1475bafc0 19 /// @endcode
WiredHome 33:d4d1475bafc0 20 ///
WiredHome 33:d4d1475bafc0 21 /// @param filename is the fully qualified filename to create.
WiredHome 33:d4d1475bafc0 22 ///
WiredHome 23:517fec8b8b99 23 HTTPFile(char* filename);
WiredHome 23:517fec8b8b99 24
WiredHome 23:517fec8b8b99 25 /** Closes the file, should be called once the http connection is closed.
WiredHome 23:517fec8b8b99 26 */
WiredHome 23:517fec8b8b99 27 void close();
WiredHome 23:517fec8b8b99 28
WiredHome 23:517fec8b8b99 29 protected:
WiredHome 23:517fec8b8b99 30
WiredHome 23:517fec8b8b99 31 friend class HTTPClient;
WiredHome 23:517fec8b8b99 32
WiredHome 23:517fec8b8b99 33 /** Reset stream to its beginning
WiredHome 23:517fec8b8b99 34 * Called by the HTTPClient on each new request
WiredHome 23:517fec8b8b99 35 */
WiredHome 23:517fec8b8b99 36 virtual void writeReset();
WiredHome 23:517fec8b8b99 37
WiredHome 23:517fec8b8b99 38 /** Write a piece of data transmitted by the server
WiredHome 32:7b9919d59194 39 * @param[in] buf Pointer to the buffer from which to copy the data
WiredHome 32:7b9919d59194 40 * @param[in] len Length of the buffer
WiredHome 32:7b9919d59194 41 * @returns number of bytes written.
WiredHome 23:517fec8b8b99 42 */
WiredHome 23:517fec8b8b99 43 virtual int write(const char* buf, size_t len);
WiredHome 23:517fec8b8b99 44
WiredHome 23:517fec8b8b99 45 /** Set MIME type
WiredHome 32:7b9919d59194 46 * @param[in] type Internet media type from Content-Type header
WiredHome 23:517fec8b8b99 47 */
WiredHome 23:517fec8b8b99 48 virtual void setDataType(const char* type);
WiredHome 23:517fec8b8b99 49
WiredHome 23:517fec8b8b99 50 /** Determine whether the data is chunked
WiredHome 23:517fec8b8b99 51 * Recovered from Transfer-Encoding header
WiredHome 32:7b9919d59194 52 * @param[in] chunked indicates the transfer is chunked.
WiredHome 23:517fec8b8b99 53 */
WiredHome 23:517fec8b8b99 54 virtual void setIsChunked(bool chunked);
WiredHome 23:517fec8b8b99 55
WiredHome 23:517fec8b8b99 56 /** If the data is not chunked, set its size
WiredHome 23:517fec8b8b99 57 * From Content-Length header
WiredHome 32:7b9919d59194 58 * @param[in] len defines the size of the non-chunked transfer.
WiredHome 23:517fec8b8b99 59 */
WiredHome 23:517fec8b8b99 60 virtual void setDataLen(size_t len);
WiredHome 23:517fec8b8b99 61 private:
WiredHome 23:517fec8b8b99 62 FILE *file;
WiredHome 23:517fec8b8b99 63 size_t m_len;
WiredHome 23:517fec8b8b99 64 bool m_chunked;
WiredHome 23:517fec8b8b99 65 };
WiredHome 25:76084defa790 66 #endif // HTTPFILE_H