A HTTP Client for the mbed networking libraries with HTTPFile for use with latest networking stack
Fork of HTTPClient by
An extension of the HTTPClient that adds HTTPFile. Currently on get is support and only works when getting binary files.
HTTPFile data("/local/firm.bin"); HTTPResult r = client.get("https://217.140.101.20/media/uploads/ollie8/firm.bin", &data); if (r == HTTP_OK) { }
data/HTTPFile.cpp@17:5cfbfcdf660a, 2013-12-30 (annotated)
- Committer:
- ollie8
- Date:
- Mon Dec 30 13:49:56 2013 +0000
- Revision:
- 17:5cfbfcdf660a
- Child:
- 18:1448391bbc51
Added implementation of HTTPFile
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ollie8 | 17:5cfbfcdf660a | 1 | #include "HTTPFile.h" |
ollie8 | 17:5cfbfcdf660a | 2 | #define DEBUG |
ollie8 | 17:5cfbfcdf660a | 3 | #include "hl_debug.h" |
ollie8 | 17:5cfbfcdf660a | 4 | |
ollie8 | 17:5cfbfcdf660a | 5 | HTTPFile::HTTPFile(char* filename) { |
ollie8 | 17:5cfbfcdf660a | 6 | file = fopen(filename, "w"); |
ollie8 | 17:5cfbfcdf660a | 7 | } |
ollie8 | 17:5cfbfcdf660a | 8 | |
ollie8 | 17:5cfbfcdf660a | 9 | void HTTPFile::close() { |
ollie8 | 17:5cfbfcdf660a | 10 | if (file) { |
ollie8 | 17:5cfbfcdf660a | 11 | fclose(file); |
ollie8 | 17:5cfbfcdf660a | 12 | } |
ollie8 | 17:5cfbfcdf660a | 13 | } |
ollie8 | 17:5cfbfcdf660a | 14 | |
ollie8 | 17:5cfbfcdf660a | 15 | void HTTPFile::writeReset() { |
ollie8 | 17:5cfbfcdf660a | 16 | if (file) { |
ollie8 | 17:5cfbfcdf660a | 17 | rewind(file); |
ollie8 | 17:5cfbfcdf660a | 18 | } |
ollie8 | 17:5cfbfcdf660a | 19 | } |
ollie8 | 17:5cfbfcdf660a | 20 | |
ollie8 | 17:5cfbfcdf660a | 21 | int HTTPFile::write(const char* buf, size_t len) { |
ollie8 | 17:5cfbfcdf660a | 22 | if (file) { |
ollie8 | 17:5cfbfcdf660a | 23 | len = fwrite(&buf, 1, len, file); |
ollie8 | 17:5cfbfcdf660a | 24 | if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !len)) { |
ollie8 | 17:5cfbfcdf660a | 25 | close(); |
ollie8 | 17:5cfbfcdf660a | 26 | } |
ollie8 | 17:5cfbfcdf660a | 27 | } |
ollie8 | 17:5cfbfcdf660a | 28 | return len; |
ollie8 | 17:5cfbfcdf660a | 29 | } |
ollie8 | 17:5cfbfcdf660a | 30 | |
ollie8 | 17:5cfbfcdf660a | 31 | void HTTPFile::setDataType(const char* type) { |
ollie8 | 17:5cfbfcdf660a | 32 | INFO("data type = %s", type); |
ollie8 | 17:5cfbfcdf660a | 33 | } |
ollie8 | 17:5cfbfcdf660a | 34 | |
ollie8 | 17:5cfbfcdf660a | 35 | void HTTPFile::setIsChunked(bool chunked) { |
ollie8 | 17:5cfbfcdf660a | 36 | m_chunked = chunked; |
ollie8 | 17:5cfbfcdf660a | 37 | } |
ollie8 | 17:5cfbfcdf660a | 38 | |
ollie8 | 17:5cfbfcdf660a | 39 | void HTTPFile::setDataLen(size_t len) { |
ollie8 | 17:5cfbfcdf660a | 40 | m_len = len; |
ollie8 | 17:5cfbfcdf660a | 41 | } |