HTTPClient

Fork of HTTPClient by Donatien Garnier

Committer:
donatien
Date:
Fri May 02 13:13:39 2014 +0000
Revision:
17:679e15a3d3db
Parent:
16:1f743885e7de
Do not block and wait for 255 bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:2ccb9960a044 1 /* IHTTPData.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 #ifndef IHTTPDATA_H
donatien 0:2ccb9960a044 21 #define IHTTPDATA_H
donatien 0:2ccb9960a044 22
donatien 13:be61104f4e91 23 #include <cstring>
donatien 13:be61104f4e91 24
donatien 13:be61104f4e91 25 using std::size_t;
donatien 13:be61104f4e91 26
donatien 17:679e15a3d3db 27 class IHTTPData
donatien 17:679e15a3d3db 28 {
donatien 17:679e15a3d3db 29 protected:
donatien 17:679e15a3d3db 30 /** Get a specific header
donatien 17:679e15a3d3db 31 *
donatien 17:679e15a3d3db 32 */
donatien 17:679e15a3d3db 33 virtual bool getHeader(char* header, size_t maxHeaderLen) { return false; }
donatien 17:679e15a3d3db 34 };
donatien 17:679e15a3d3db 35
donatien 0:2ccb9960a044 36 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
donatien 17:679e15a3d3db 37 class IHTTPDataOut : public IHTTPData
donatien 0:2ccb9960a044 38 {
donatien 0:2ccb9960a044 39 protected:
donatien 0:2ccb9960a044 40 friend class HTTPClient;
donatien 16:1f743885e7de 41
donatien 16:1f743885e7de 42 /** Reset stream to its beginning
donatien 16:1f743885e7de 43 * Called by the HTTPClient on each new request
donatien 16:1f743885e7de 44 */
donatien 16:1f743885e7de 45 virtual void readReset() = 0;
donatien 0:2ccb9960a044 46
donatien 0:2ccb9960a044 47 /** Read a piece of data to be transmitted
donatien 0:2ccb9960a044 48 * @param buf Pointer to the buffer on which to copy the data
donatien 0:2ccb9960a044 49 * @param len Length of the buffer
donatien 0:2ccb9960a044 50 * @param pReadLen Pointer to the variable on which the actual copied data length will be stored
donatien 0:2ccb9960a044 51 */
donatien 0:2ccb9960a044 52 virtual int read(char* buf, size_t len, size_t* pReadLen) = 0;
donatien 0:2ccb9960a044 53
donatien 0:2ccb9960a044 54 /** Get MIME type
donatien 0:2ccb9960a044 55 * @param type Internet media type from Content-Type header
donatien 0:2ccb9960a044 56 */
donatien 0:2ccb9960a044 57 virtual int getDataType(char* type, size_t maxTypeLen) = 0; //Internet media type for Content-Type header
donatien 0:2ccb9960a044 58
donatien 0:2ccb9960a044 59 /** Determine whether the HTTP client should chunk the data
donatien 0:2ccb9960a044 60 * Used for Transfer-Encoding header
donatien 0:2ccb9960a044 61 */
donatien 0:2ccb9960a044 62 virtual bool getIsChunked() = 0;
donatien 0:2ccb9960a044 63
donatien 0:2ccb9960a044 64 /** If the data is not chunked, get its size
donatien 0:2ccb9960a044 65 * Used for Content-Length header
donatien 0:2ccb9960a044 66 */
donatien 0:2ccb9960a044 67 virtual size_t getDataLen() = 0;
donatien 0:2ccb9960a044 68
donatien 0:2ccb9960a044 69 };
donatien 0:2ccb9960a044 70
donatien 0:2ccb9960a044 71 ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...)
donatien 17:679e15a3d3db 72 class IHTTPDataIn : public IHTTPData
donatien 0:2ccb9960a044 73 {
donatien 0:2ccb9960a044 74 protected:
donatien 0:2ccb9960a044 75 friend class HTTPClient;
donatien 0:2ccb9960a044 76
donatien 16:1f743885e7de 77 /** Reset stream to its beginning
donatien 16:1f743885e7de 78 * Called by the HTTPClient on each new request
donatien 16:1f743885e7de 79 */
donatien 16:1f743885e7de 80 virtual void writeReset() = 0;
donatien 16:1f743885e7de 81
donatien 0:2ccb9960a044 82 /** Write a piece of data transmitted by the server
donatien 0:2ccb9960a044 83 * @param buf Pointer to the buffer from which to copy the data
donatien 0:2ccb9960a044 84 * @param len Length of the buffer
donatien 0:2ccb9960a044 85 */
donatien 0:2ccb9960a044 86 virtual int write(const char* buf, size_t len) = 0;
donatien 0:2ccb9960a044 87
donatien 0:2ccb9960a044 88 /** Set MIME type
donatien 0:2ccb9960a044 89 * @param type Internet media type from Content-Type header
donatien 0:2ccb9960a044 90 */
donatien 0:2ccb9960a044 91 virtual void setDataType(const char* type) = 0;
donatien 0:2ccb9960a044 92
donatien 0:2ccb9960a044 93 /** Determine whether the data is chunked
donatien 0:2ccb9960a044 94 * Recovered from Transfer-Encoding header
donatien 0:2ccb9960a044 95 */
donatien 0:2ccb9960a044 96 virtual void setIsChunked(bool chunked) = 0;
donatien 0:2ccb9960a044 97
donatien 0:2ccb9960a044 98 /** If the data is not chunked, set its size
donatien 0:2ccb9960a044 99 * From Content-Length header
donatien 0:2ccb9960a044 100 */
donatien 0:2ccb9960a044 101 virtual void setDataLen(size_t len) = 0;
donatien 0:2ccb9960a044 102
donatien 0:2ccb9960a044 103 };
donatien 0:2ccb9960a044 104
donatien 0:2ccb9960a044 105 #endif