httpclient

Dependents:   Lab_6

Committer:
rr387
Date:
Thu Dec 30 15:21:34 2021 +0000
Revision:
0:a988a72f184b
retes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rr387 0:a988a72f184b 1 /* HTTPText.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
rr387 0:a988a72f184b 21 #ifndef HTTPTEXT_H_
rr387 0:a988a72f184b 22 #define HTTPTEXT_H_
rr387 0:a988a72f184b 23
rr387 0:a988a72f184b 24 #include "../IHTTPData.h"
rr387 0:a988a72f184b 25
rr387 0:a988a72f184b 26 /** A data endpoint to store text
rr387 0:a988a72f184b 27 */
rr387 0:a988a72f184b 28 class HTTPText : public IHTTPDataIn, public IHTTPDataOut
rr387 0:a988a72f184b 29 {
rr387 0:a988a72f184b 30 public:
rr387 0:a988a72f184b 31 /** Create an HTTPText instance for output
rr387 0:a988a72f184b 32 * @param str String to be transmitted
rr387 0:a988a72f184b 33 */
rr387 0:a988a72f184b 34 HTTPText(char* str);
rr387 0:a988a72f184b 35
rr387 0:a988a72f184b 36 /** Create an HTTPText instance for input
rr387 0:a988a72f184b 37 * @param str Buffer to store the incoming string
rr387 0:a988a72f184b 38 * @param size Size of the buffer
rr387 0:a988a72f184b 39 */
rr387 0:a988a72f184b 40 HTTPText(char* str, size_t size);
rr387 0:a988a72f184b 41
rr387 0:a988a72f184b 42 protected:
rr387 0:a988a72f184b 43 //IHTTPDataIn
rr387 0:a988a72f184b 44 virtual void readReset();
rr387 0:a988a72f184b 45
rr387 0:a988a72f184b 46 virtual int read(char* buf, size_t len, size_t* pReadLen);
rr387 0:a988a72f184b 47
rr387 0:a988a72f184b 48 virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
rr387 0:a988a72f184b 49
rr387 0:a988a72f184b 50 virtual bool getIsChunked(); //For Transfer-Encoding header
rr387 0:a988a72f184b 51
rr387 0:a988a72f184b 52 virtual size_t getDataLen(); //For Content-Length header
rr387 0:a988a72f184b 53
rr387 0:a988a72f184b 54 //IHTTPDataOut
rr387 0:a988a72f184b 55 virtual void writeReset();
rr387 0:a988a72f184b 56
rr387 0:a988a72f184b 57 virtual int write(const char* buf, size_t len);
rr387 0:a988a72f184b 58
rr387 0:a988a72f184b 59 virtual void setDataType(const char* type); //Internet media type from Content-Type header
rr387 0:a988a72f184b 60
rr387 0:a988a72f184b 61 virtual void setIsChunked(bool chunked); //From Transfer-Encoding header
rr387 0:a988a72f184b 62
rr387 0:a988a72f184b 63 virtual void setDataLen(size_t len); //From Content-Length header, or if the transfer is chunked, next chunk length
rr387 0:a988a72f184b 64
rr387 0:a988a72f184b 65 private:
rr387 0:a988a72f184b 66 char* m_str;
rr387 0:a988a72f184b 67 size_t m_size;
rr387 0:a988a72f184b 68
rr387 0:a988a72f184b 69 size_t m_pos;
rr387 0:a988a72f184b 70 };
rr387 0:a988a72f184b 71
rr387 0:a988a72f184b 72 #endif /* HTTPTEXT_H_ */