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) {
                            
}

data/HTTPFile.cpp

Committer:
ollie8
Date:
2013-12-31
Revision:
18:1448391bbc51
Parent:
17:5cfbfcdf660a
Child:
19:bc765a7fd8f2

File content as of revision 18:1448391bbc51:

#include "HTTPFile.h"

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;
}