It is the new miniTLS program which build the connect with the website httpbin.org
Fork of MiniTLS-HTTPSClient by
IHTTPData.h@0:62a4a8ec4ab5, 2014-06-10 (annotated)
- Committer:
- MiniTLS
- Date:
- Tue Jun 10 14:23:22 2014 +0000
- Revision:
- 0:62a4a8ec4ab5
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MiniTLS | 0:62a4a8ec4ab5 | 1 | /* IHTTPData.h */ |
MiniTLS | 0:62a4a8ec4ab5 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
MiniTLS | 0:62a4a8ec4ab5 | 3 | * |
MiniTLS | 0:62a4a8ec4ab5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
MiniTLS | 0:62a4a8ec4ab5 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
MiniTLS | 0:62a4a8ec4ab5 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
MiniTLS | 0:62a4a8ec4ab5 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
MiniTLS | 0:62a4a8ec4ab5 | 8 | * furnished to do so, subject to the following conditions: |
MiniTLS | 0:62a4a8ec4ab5 | 9 | * |
MiniTLS | 0:62a4a8ec4ab5 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
MiniTLS | 0:62a4a8ec4ab5 | 11 | * substantial portions of the Software. |
MiniTLS | 0:62a4a8ec4ab5 | 12 | * |
MiniTLS | 0:62a4a8ec4ab5 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
MiniTLS | 0:62a4a8ec4ab5 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
MiniTLS | 0:62a4a8ec4ab5 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
MiniTLS | 0:62a4a8ec4ab5 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MiniTLS | 0:62a4a8ec4ab5 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
MiniTLS | 0:62a4a8ec4ab5 | 18 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 19 | |
MiniTLS | 0:62a4a8ec4ab5 | 20 | #ifndef IHTTPDATA_H |
MiniTLS | 0:62a4a8ec4ab5 | 21 | #define IHTTPDATA_H |
MiniTLS | 0:62a4a8ec4ab5 | 22 | |
MiniTLS | 0:62a4a8ec4ab5 | 23 | #include <cstring> |
MiniTLS | 0:62a4a8ec4ab5 | 24 | |
MiniTLS | 0:62a4a8ec4ab5 | 25 | #include "core/fwk.h" |
MiniTLS | 0:62a4a8ec4ab5 | 26 | |
MiniTLS | 0:62a4a8ec4ab5 | 27 | class IHTTPData |
MiniTLS | 0:62a4a8ec4ab5 | 28 | { |
MiniTLS | 0:62a4a8ec4ab5 | 29 | protected: |
MiniTLS | 0:62a4a8ec4ab5 | 30 | /** Get a specific header |
MiniTLS | 0:62a4a8ec4ab5 | 31 | * |
MiniTLS | 0:62a4a8ec4ab5 | 32 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 33 | virtual bool getHeader(char* header, size_t maxHeaderLen) { return false; } |
MiniTLS | 0:62a4a8ec4ab5 | 34 | }; |
MiniTLS | 0:62a4a8ec4ab5 | 35 | |
MiniTLS | 0:62a4a8ec4ab5 | 36 | ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...) |
MiniTLS | 0:62a4a8ec4ab5 | 37 | class IHTTPDataOut : public IHTTPData |
MiniTLS | 0:62a4a8ec4ab5 | 38 | { |
MiniTLS | 0:62a4a8ec4ab5 | 39 | protected: |
MiniTLS | 0:62a4a8ec4ab5 | 40 | friend class HTTPClient; |
MiniTLS | 0:62a4a8ec4ab5 | 41 | |
MiniTLS | 0:62a4a8ec4ab5 | 42 | /** Reset stream to its beginning |
MiniTLS | 0:62a4a8ec4ab5 | 43 | * Called by the HTTPClient on each new request |
MiniTLS | 0:62a4a8ec4ab5 | 44 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 45 | virtual void readReset() = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 46 | |
MiniTLS | 0:62a4a8ec4ab5 | 47 | /** Read a piece of data to be transmitted |
MiniTLS | 0:62a4a8ec4ab5 | 48 | * @param buf Pointer to the buffer on which to copy the data |
MiniTLS | 0:62a4a8ec4ab5 | 49 | * @param len Length of the buffer |
MiniTLS | 0:62a4a8ec4ab5 | 50 | * @param pReadLen Pointer to the variable on which the actual copied data length will be stored |
MiniTLS | 0:62a4a8ec4ab5 | 51 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 52 | virtual int read(char* buf, size_t len, size_t* pReadLen) = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 53 | |
MiniTLS | 0:62a4a8ec4ab5 | 54 | /** Get MIME type |
MiniTLS | 0:62a4a8ec4ab5 | 55 | * @param type Internet media type from Content-Type header |
MiniTLS | 0:62a4a8ec4ab5 | 56 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 57 | virtual int getDataType(char* type, size_t maxTypeLen) = 0; //Internet media type for Content-Type header |
MiniTLS | 0:62a4a8ec4ab5 | 58 | |
MiniTLS | 0:62a4a8ec4ab5 | 59 | /** Determine whether the HTTP client should chunk the data |
MiniTLS | 0:62a4a8ec4ab5 | 60 | * Used for Transfer-Encoding header |
MiniTLS | 0:62a4a8ec4ab5 | 61 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 62 | virtual bool getIsChunked() = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 63 | |
MiniTLS | 0:62a4a8ec4ab5 | 64 | /** If the data is not chunked, get its size |
MiniTLS | 0:62a4a8ec4ab5 | 65 | * Used for Content-Length header |
MiniTLS | 0:62a4a8ec4ab5 | 66 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 67 | virtual size_t getDataLen() = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 68 | |
MiniTLS | 0:62a4a8ec4ab5 | 69 | }; |
MiniTLS | 0:62a4a8ec4ab5 | 70 | |
MiniTLS | 0:62a4a8ec4ab5 | 71 | ///This is a simple interface for HTTP data storage (impl examples are Key/Value Pairs, File, etc...) |
MiniTLS | 0:62a4a8ec4ab5 | 72 | class IHTTPDataIn : public IHTTPData |
MiniTLS | 0:62a4a8ec4ab5 | 73 | { |
MiniTLS | 0:62a4a8ec4ab5 | 74 | protected: |
MiniTLS | 0:62a4a8ec4ab5 | 75 | friend class HTTPClient; |
MiniTLS | 0:62a4a8ec4ab5 | 76 | |
MiniTLS | 0:62a4a8ec4ab5 | 77 | /** Reset stream to its beginning |
MiniTLS | 0:62a4a8ec4ab5 | 78 | * Called by the HTTPClient on each new request |
MiniTLS | 0:62a4a8ec4ab5 | 79 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 80 | virtual void writeReset() = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 81 | |
MiniTLS | 0:62a4a8ec4ab5 | 82 | /** Write a piece of data transmitted by the server |
MiniTLS | 0:62a4a8ec4ab5 | 83 | * @param buf Pointer to the buffer from which to copy the data |
MiniTLS | 0:62a4a8ec4ab5 | 84 | * @param len Length of the buffer |
MiniTLS | 0:62a4a8ec4ab5 | 85 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 86 | virtual int write(const char* buf, size_t len) = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 87 | |
MiniTLS | 0:62a4a8ec4ab5 | 88 | /** Set MIME type |
MiniTLS | 0:62a4a8ec4ab5 | 89 | * @param type Internet media type from Content-Type header |
MiniTLS | 0:62a4a8ec4ab5 | 90 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 91 | virtual void setDataType(const char* type) = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 92 | |
MiniTLS | 0:62a4a8ec4ab5 | 93 | /** Determine whether the data is chunked |
MiniTLS | 0:62a4a8ec4ab5 | 94 | * Recovered from Transfer-Encoding header |
MiniTLS | 0:62a4a8ec4ab5 | 95 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 96 | virtual void setIsChunked(bool chunked) = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 97 | |
MiniTLS | 0:62a4a8ec4ab5 | 98 | /** If the data is not chunked, set its size |
MiniTLS | 0:62a4a8ec4ab5 | 99 | * From Content-Length header |
MiniTLS | 0:62a4a8ec4ab5 | 100 | */ |
MiniTLS | 0:62a4a8ec4ab5 | 101 | virtual void setDataLen(size_t len) = 0; |
MiniTLS | 0:62a4a8ec4ab5 | 102 | |
MiniTLS | 0:62a4a8ec4ab5 | 103 | }; |
MiniTLS | 0:62a4a8ec4ab5 | 104 | |
MiniTLS | 0:62a4a8ec4ab5 | 105 | #endif |