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:
2015-07-26
Revision:
19:bc765a7fd8f2
Parent:
18:1448391bbc51

File content as of revision 19:bc765a7fd8f2:

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