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:
donatien
Date:
Thu Aug 30 15:38:57 2012 +0000
Revision:
16:1f743885e7de
Parent:
10:e1351de84c16
IHTTPData (HTTPText, HTTPMap) objects can be re-used multiple times (reading/writing position is reset on each connection); Support for PUT and DELETE methods

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:2ccb9960a044 1 /* HTTPText.h */
donatien 10:e1351de84c16 2 /* Copyright (C) 2012 mbed.org, MIT License
donatien 10:e1351de84c16 3 *
donatien 10:e1351de84c16 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 10:e1351de84c16 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
donatien 10:e1351de84c16 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
donatien 10:e1351de84c16 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
donatien 10:e1351de84c16 8 * furnished to do so, subject to the following conditions:
donatien 10:e1351de84c16 9 *
donatien 10:e1351de84c16 10 * The above copyright notice and this permission notice shall be included in all copies or
donatien 10:e1351de84c16 11 * substantial portions of the Software.
donatien 10:e1351de84c16 12 *
donatien 10:e1351de84c16 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 10:e1351de84c16 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 10:e1351de84c16 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 10:e1351de84c16 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 10:e1351de84c16 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 10:e1351de84c16 18 */
donatien 0:2ccb9960a044 19
donatien 0:2ccb9960a044 20
donatien 0:2ccb9960a044 21 #ifndef HTTPTEXT_H_
donatien 0:2ccb9960a044 22 #define HTTPTEXT_H_
donatien 0:2ccb9960a044 23
donatien 0:2ccb9960a044 24 #include "../IHTTPData.h"
donatien 0:2ccb9960a044 25
donatien 0:2ccb9960a044 26 /** A data endpoint to store text
donatien 0:2ccb9960a044 27 */
donatien 0:2ccb9960a044 28 class HTTPText : public IHTTPDataIn, public IHTTPDataOut
donatien 0:2ccb9960a044 29 {
donatien 0:2ccb9960a044 30 public:
donatien 0:2ccb9960a044 31 /** Create an HTTPText instance for output
donatien 0:2ccb9960a044 32 * @param str String to be transmitted
donatien 0:2ccb9960a044 33 */
donatien 0:2ccb9960a044 34 HTTPText(char* str);
donatien 0:2ccb9960a044 35
donatien 0:2ccb9960a044 36 /** Create an HTTPText instance for input
donatien 0:2ccb9960a044 37 * @param str Buffer to store the incoming string
donatien 0:2ccb9960a044 38 * @param size Size of the buffer
donatien 0:2ccb9960a044 39 */
donatien 0:2ccb9960a044 40 HTTPText(char* str, size_t size);
donatien 0:2ccb9960a044 41
donatien 0:2ccb9960a044 42 protected:
donatien 0:2ccb9960a044 43 //IHTTPDataIn
donatien 16:1f743885e7de 44 virtual void readReset();
donatien 16:1f743885e7de 45
donatien 0:2ccb9960a044 46 virtual int read(char* buf, size_t len, size_t* pReadLen);
donatien 0:2ccb9960a044 47
donatien 0:2ccb9960a044 48 virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
donatien 0:2ccb9960a044 49
donatien 0:2ccb9960a044 50 virtual bool getIsChunked(); //For Transfer-Encoding header
donatien 0:2ccb9960a044 51
donatien 0:2ccb9960a044 52 virtual size_t getDataLen(); //For Content-Length header
donatien 0:2ccb9960a044 53
donatien 0:2ccb9960a044 54 //IHTTPDataOut
donatien 16:1f743885e7de 55 virtual void writeReset();
donatien 16:1f743885e7de 56
donatien 0:2ccb9960a044 57 virtual int write(const char* buf, size_t len);
donatien 0:2ccb9960a044 58
donatien 0:2ccb9960a044 59 virtual void setDataType(const char* type); //Internet media type from Content-Type header
donatien 0:2ccb9960a044 60
donatien 0:2ccb9960a044 61 virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
donatien 0:2ccb9960a044 62
donatien 0:2ccb9960a044 63 virtual void setDataLen(size_t len); //From Content-Length header, or if the transfer is chunked, next chunk length
donatien 0:2ccb9960a044 64
donatien 0:2ccb9960a044 65 private:
donatien 0:2ccb9960a044 66 char* m_str;
donatien 0:2ccb9960a044 67 size_t m_size;
donatien 0:2ccb9960a044 68
donatien 0:2ccb9960a044 69 size_t m_pos;
donatien 0:2ccb9960a044 70 };
donatien 0:2ccb9960a044 71
donatien 0:2ccb9960a044 72 #endif /* HTTPTEXT_H_ */