A HTTP Client for the mbed networking libraries with HTTPFile for use with latest networking stack

Fork of HTTPClient by Donatien Garnier

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) {
                            
}
Committer:
ollie8
Date:
Sun Jul 26 09:02:21 2015 +0000
Revision:
19:bc765a7fd8f2
Parent:
18:1448391bbc51
Fixed bug in file write method

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ollie8 17:5cfbfcdf660a 1 #include "HTTPFile.h"
ollie8 17:5cfbfcdf660a 2
ollie8 17:5cfbfcdf660a 3 HTTPFile::HTTPFile(char* filename) {
ollie8 17:5cfbfcdf660a 4 file = fopen(filename, "w");
ollie8 17:5cfbfcdf660a 5 }
ollie8 17:5cfbfcdf660a 6
ollie8 17:5cfbfcdf660a 7 void HTTPFile::close() {
ollie8 17:5cfbfcdf660a 8 if (file) {
ollie8 17:5cfbfcdf660a 9 fclose(file);
ollie8 17:5cfbfcdf660a 10 }
ollie8 17:5cfbfcdf660a 11 }
ollie8 17:5cfbfcdf660a 12
ollie8 17:5cfbfcdf660a 13 void HTTPFile::writeReset() {
ollie8 17:5cfbfcdf660a 14 if (file) {
ollie8 17:5cfbfcdf660a 15 rewind(file);
ollie8 17:5cfbfcdf660a 16 }
ollie8 17:5cfbfcdf660a 17 }
ollie8 17:5cfbfcdf660a 18
ollie8 17:5cfbfcdf660a 19 int HTTPFile::write(const char* buf, size_t len) {
ollie8 17:5cfbfcdf660a 20 if (file) {
ollie8 19:bc765a7fd8f2 21 len = fwrite(buf, 1, len, file);
ollie8 17:5cfbfcdf660a 22 if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !len)) {
ollie8 17:5cfbfcdf660a 23 close();
ollie8 17:5cfbfcdf660a 24 }
ollie8 17:5cfbfcdf660a 25 }
ollie8 17:5cfbfcdf660a 26 return len;
ollie8 17:5cfbfcdf660a 27 }
ollie8 17:5cfbfcdf660a 28
ollie8 17:5cfbfcdf660a 29 void HTTPFile::setDataType(const char* type) {
ollie8 18:1448391bbc51 30
ollie8 17:5cfbfcdf660a 31 }
ollie8 17:5cfbfcdf660a 32
ollie8 17:5cfbfcdf660a 33 void HTTPFile::setIsChunked(bool chunked) {
ollie8 17:5cfbfcdf660a 34 m_chunked = chunked;
ollie8 17:5cfbfcdf660a 35 }
ollie8 17:5cfbfcdf660a 36
ollie8 17:5cfbfcdf660a 37 void HTTPFile::setDataLen(size_t len) {
ollie8 17:5cfbfcdf660a 38 m_len = len;
ollie8 17:5cfbfcdf660a 39 }