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