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 /* HTTPMap.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 HTTPMAP_H_
rr387 0:a988a72f184b 22 #define HTTPMAP_H_
rr387 0:a988a72f184b 23
rr387 0:a988a72f184b 24 #include "../IHTTPData.h"
rr387 0:a988a72f184b 25
rr387 0:a988a72f184b 26 #define HTTPMAP_TABLE_SIZE 32
rr387 0:a988a72f184b 27
rr387 0:a988a72f184b 28 /** Map of key/value pairs
rr387 0:a988a72f184b 29 * Used to transmit POST data using the application/x-www-form-urlencoded encoding
rr387 0:a988a72f184b 30 */
rr387 0:a988a72f184b 31 class HTTPMap: public IHTTPDataOut
rr387 0:a988a72f184b 32 {
rr387 0:a988a72f184b 33 public:
rr387 0:a988a72f184b 34 /**
rr387 0:a988a72f184b 35 Instantiates HTTPMap
rr387 0:a988a72f184b 36 It supports at most 32 key/values pairs
rr387 0:a988a72f184b 37 */
rr387 0:a988a72f184b 38 HTTPMap();
rr387 0:a988a72f184b 39
rr387 0:a988a72f184b 40 /** Put Key/Value pair
rr387 0:a988a72f184b 41 The references to the parameters must remain valid as long as the clear() function is not called
rr387 0:a988a72f184b 42 @param key The key to use
rr387 0:a988a72f184b 43 @param value The corresponding value
rr387 0:a988a72f184b 44 */
rr387 0:a988a72f184b 45 void put(const char* key, const char* value);
rr387 0:a988a72f184b 46
rr387 0:a988a72f184b 47 /** Clear table
rr387 0:a988a72f184b 48 */
rr387 0:a988a72f184b 49 void clear();
rr387 0:a988a72f184b 50
rr387 0:a988a72f184b 51 protected:
rr387 0:a988a72f184b 52 //IHTTPDataIn
rr387 0:a988a72f184b 53 virtual void readReset();
rr387 0:a988a72f184b 54
rr387 0:a988a72f184b 55 virtual int read(char* buf, size_t len, size_t* pReadLen);
rr387 0:a988a72f184b 56
rr387 0:a988a72f184b 57 virtual int getDataType(char* type, size_t maxTypeLen); //Internet media type for Content-Type header
rr387 0:a988a72f184b 58
rr387 0:a988a72f184b 59 virtual bool getIsChunked(); //For Transfer-Encoding header
rr387 0:a988a72f184b 60
rr387 0:a988a72f184b 61 virtual size_t getDataLen(); //For Content-Length header
rr387 0:a988a72f184b 62
rr387 0:a988a72f184b 63 private:
rr387 0:a988a72f184b 64 const char* m_keys[HTTPMAP_TABLE_SIZE];
rr387 0:a988a72f184b 65 const char* m_values[HTTPMAP_TABLE_SIZE];
rr387 0:a988a72f184b 66
rr387 0:a988a72f184b 67 size_t m_pos;
rr387 0:a988a72f184b 68 size_t m_count;
rr387 0:a988a72f184b 69 };
rr387 0:a988a72f184b 70
rr387 0:a988a72f184b 71 #endif /* HTTPMAP_H_ */