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