joshua Elsdon
/
Email2Screen
Mac addr added ICRS
Fork of Email2Screen by
NetServicesProxy/services/http/client/HTTPClient.h@0:1619a6b826d7, 2011-11-21 (annotated)
- Committer:
- Hello1024
- Date:
- Mon Nov 21 18:25:34 2011 +0000
- Revision:
- 0:1619a6b826d7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hello1024 | 0:1619a6b826d7 | 1 | |
Hello1024 | 0:1619a6b826d7 | 2 | /* |
Hello1024 | 0:1619a6b826d7 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
Hello1024 | 0:1619a6b826d7 | 4 | |
Hello1024 | 0:1619a6b826d7 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
Hello1024 | 0:1619a6b826d7 | 6 | of this software and associated documentation files (the "Software"), to deal |
Hello1024 | 0:1619a6b826d7 | 7 | in the Software without restriction, including without limitation the rights |
Hello1024 | 0:1619a6b826d7 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Hello1024 | 0:1619a6b826d7 | 9 | copies of the Software, and to permit persons to whom the Software is |
Hello1024 | 0:1619a6b826d7 | 10 | furnished to do so, subject to the following conditions: |
Hello1024 | 0:1619a6b826d7 | 11 | |
Hello1024 | 0:1619a6b826d7 | 12 | The above copyright notice and this permission notice shall be included in |
Hello1024 | 0:1619a6b826d7 | 13 | all copies or substantial portions of the Software. |
Hello1024 | 0:1619a6b826d7 | 14 | |
Hello1024 | 0:1619a6b826d7 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Hello1024 | 0:1619a6b826d7 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Hello1024 | 0:1619a6b826d7 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Hello1024 | 0:1619a6b826d7 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Hello1024 | 0:1619a6b826d7 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Hello1024 | 0:1619a6b826d7 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Hello1024 | 0:1619a6b826d7 | 21 | THE SOFTWARE. |
Hello1024 | 0:1619a6b826d7 | 22 | */ |
Hello1024 | 0:1619a6b826d7 | 23 | |
Hello1024 | 0:1619a6b826d7 | 24 | /** \file |
Hello1024 | 0:1619a6b826d7 | 25 | HTTP Client header file |
Hello1024 | 0:1619a6b826d7 | 26 | */ |
Hello1024 | 0:1619a6b826d7 | 27 | |
Hello1024 | 0:1619a6b826d7 | 28 | #ifndef HTTP_CLIENT_H |
Hello1024 | 0:1619a6b826d7 | 29 | #define HTTP_CLIENT_H |
Hello1024 | 0:1619a6b826d7 | 30 | |
Hello1024 | 0:1619a6b826d7 | 31 | class HTTPData; |
Hello1024 | 0:1619a6b826d7 | 32 | |
Hello1024 | 0:1619a6b826d7 | 33 | #include "core/net.h" |
Hello1024 | 0:1619a6b826d7 | 34 | #include "api/TCPSocket.h" |
Hello1024 | 0:1619a6b826d7 | 35 | #include "api/DNSRequest.h" |
Hello1024 | 0:1619a6b826d7 | 36 | #include "HTTPData.h" |
Hello1024 | 0:1619a6b826d7 | 37 | #include "mbed.h" |
Hello1024 | 0:1619a6b826d7 | 38 | |
Hello1024 | 0:1619a6b826d7 | 39 | #include <string> |
Hello1024 | 0:1619a6b826d7 | 40 | using std::string; |
Hello1024 | 0:1619a6b826d7 | 41 | |
Hello1024 | 0:1619a6b826d7 | 42 | #include <map> |
Hello1024 | 0:1619a6b826d7 | 43 | using std::map; |
Hello1024 | 0:1619a6b826d7 | 44 | |
Hello1024 | 0:1619a6b826d7 | 45 | ///HTTP client results |
Hello1024 | 0:1619a6b826d7 | 46 | enum HTTPResult |
Hello1024 | 0:1619a6b826d7 | 47 | { |
Hello1024 | 0:1619a6b826d7 | 48 | HTTP_OK, ///<Success |
Hello1024 | 0:1619a6b826d7 | 49 | HTTP_PROCESSING, ///<Processing |
Hello1024 | 0:1619a6b826d7 | 50 | HTTP_PARSE, ///<URI Parse error |
Hello1024 | 0:1619a6b826d7 | 51 | HTTP_DNS, ///<Could not resolve name |
Hello1024 | 0:1619a6b826d7 | 52 | HTTP_PRTCL, ///<Protocol error |
Hello1024 | 0:1619a6b826d7 | 53 | HTTP_NOTFOUND, ///<HTTP 404 Error |
Hello1024 | 0:1619a6b826d7 | 54 | HTTP_REFUSED, ///<HTTP 403 Error |
Hello1024 | 0:1619a6b826d7 | 55 | HTTP_ERROR, ///<HTTP xxx error |
Hello1024 | 0:1619a6b826d7 | 56 | HTTP_TIMEOUT, ///<Connection timeout |
Hello1024 | 0:1619a6b826d7 | 57 | HTTP_CONN ///<Connection error |
Hello1024 | 0:1619a6b826d7 | 58 | }; |
Hello1024 | 0:1619a6b826d7 | 59 | |
Hello1024 | 0:1619a6b826d7 | 60 | #include "core/netservice.h" |
Hello1024 | 0:1619a6b826d7 | 61 | |
Hello1024 | 0:1619a6b826d7 | 62 | ///A simple HTTP Client |
Hello1024 | 0:1619a6b826d7 | 63 | /** |
Hello1024 | 0:1619a6b826d7 | 64 | The HTTPClient is composed of: |
Hello1024 | 0:1619a6b826d7 | 65 | - The actual client (HTTPClient) |
Hello1024 | 0:1619a6b826d7 | 66 | - Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes) |
Hello1024 | 0:1619a6b826d7 | 67 | */ |
Hello1024 | 0:1619a6b826d7 | 68 | class HTTPClient : protected NetService |
Hello1024 | 0:1619a6b826d7 | 69 | { |
Hello1024 | 0:1619a6b826d7 | 70 | public: |
Hello1024 | 0:1619a6b826d7 | 71 | ///Instantiates the HTTP client |
Hello1024 | 0:1619a6b826d7 | 72 | HTTPClient(); |
Hello1024 | 0:1619a6b826d7 | 73 | virtual ~HTTPClient(); |
Hello1024 | 0:1619a6b826d7 | 74 | |
Hello1024 | 0:1619a6b826d7 | 75 | ///Provides a basic authentification feature (Base64 encoded username and password) |
Hello1024 | 0:1619a6b826d7 | 76 | void basicAuth(const char* user, const char* password); //Basic Authentification |
Hello1024 | 0:1619a6b826d7 | 77 | |
Hello1024 | 0:1619a6b826d7 | 78 | //High Level setup functions |
Hello1024 | 0:1619a6b826d7 | 79 | ///Executes a GET Request (blocking) |
Hello1024 | 0:1619a6b826d7 | 80 | /** |
Hello1024 | 0:1619a6b826d7 | 81 | Executes a GET request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 82 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 83 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 84 | Blocks until completion |
Hello1024 | 0:1619a6b826d7 | 85 | */ |
Hello1024 | 0:1619a6b826d7 | 86 | HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking |
Hello1024 | 0:1619a6b826d7 | 87 | |
Hello1024 | 0:1619a6b826d7 | 88 | ///Executes a GET Request (non blocking) |
Hello1024 | 0:1619a6b826d7 | 89 | /** |
Hello1024 | 0:1619a6b826d7 | 90 | Executes a GET request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 91 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 92 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 93 | @param pMethod : callback function |
Hello1024 | 0:1619a6b826d7 | 94 | The function returns immediately and calls the callback on completion or error |
Hello1024 | 0:1619a6b826d7 | 95 | */ |
Hello1024 | 0:1619a6b826d7 | 96 | HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking |
Hello1024 | 0:1619a6b826d7 | 97 | |
Hello1024 | 0:1619a6b826d7 | 98 | ///Executes a GET Request (non blocking) |
Hello1024 | 0:1619a6b826d7 | 99 | /** |
Hello1024 | 0:1619a6b826d7 | 100 | Executes a GET request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 101 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 102 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 103 | @param pItem : instance of class on which to execute the callback method |
Hello1024 | 0:1619a6b826d7 | 104 | @param pMethod : callback method |
Hello1024 | 0:1619a6b826d7 | 105 | The function returns immediately and calls the callback on completion or error |
Hello1024 | 0:1619a6b826d7 | 106 | */ |
Hello1024 | 0:1619a6b826d7 | 107 | template<class T> |
Hello1024 | 0:1619a6b826d7 | 108 | HTTPResult get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking |
Hello1024 | 0:1619a6b826d7 | 109 | { |
Hello1024 | 0:1619a6b826d7 | 110 | setOnResult(pItem, pMethod); |
Hello1024 | 0:1619a6b826d7 | 111 | doGet(uri, pDataIn); |
Hello1024 | 0:1619a6b826d7 | 112 | return HTTP_PROCESSING; |
Hello1024 | 0:1619a6b826d7 | 113 | } |
Hello1024 | 0:1619a6b826d7 | 114 | |
Hello1024 | 0:1619a6b826d7 | 115 | ///Executes a POST Request (blocking) |
Hello1024 | 0:1619a6b826d7 | 116 | /** |
Hello1024 | 0:1619a6b826d7 | 117 | Executes a POST request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 118 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 119 | @param dataOut : a HTTPData instance that contains the data that will be posted |
Hello1024 | 0:1619a6b826d7 | 120 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 121 | Blocks until completion |
Hello1024 | 0:1619a6b826d7 | 122 | */ |
Hello1024 | 0:1619a6b826d7 | 123 | HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking |
Hello1024 | 0:1619a6b826d7 | 124 | |
Hello1024 | 0:1619a6b826d7 | 125 | ///Executes a POST Request (non blocking) |
Hello1024 | 0:1619a6b826d7 | 126 | /** |
Hello1024 | 0:1619a6b826d7 | 127 | Executes a POST request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 128 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 129 | @param dataOut : a HTTPData instance that contains the data that will be posted |
Hello1024 | 0:1619a6b826d7 | 130 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 131 | @param pMethod : callback function |
Hello1024 | 0:1619a6b826d7 | 132 | The function returns immediately and calls the callback on completion or error |
Hello1024 | 0:1619a6b826d7 | 133 | */ |
Hello1024 | 0:1619a6b826d7 | 134 | HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking |
Hello1024 | 0:1619a6b826d7 | 135 | |
Hello1024 | 0:1619a6b826d7 | 136 | ///Executes a POST Request (non blocking) |
Hello1024 | 0:1619a6b826d7 | 137 | /** |
Hello1024 | 0:1619a6b826d7 | 138 | Executes a POST request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 139 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 140 | @param dataOut : a HTTPData instance that contains the data that will be posted |
Hello1024 | 0:1619a6b826d7 | 141 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 142 | @param pItem : instance of class on which to execute the callback method |
Hello1024 | 0:1619a6b826d7 | 143 | @param pMethod : callback method |
Hello1024 | 0:1619a6b826d7 | 144 | The function returns immediately and calls the callback on completion or error |
Hello1024 | 0:1619a6b826d7 | 145 | */ |
Hello1024 | 0:1619a6b826d7 | 146 | template<class T> |
Hello1024 | 0:1619a6b826d7 | 147 | HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking |
Hello1024 | 0:1619a6b826d7 | 148 | { |
Hello1024 | 0:1619a6b826d7 | 149 | setOnResult(pItem, pMethod); |
Hello1024 | 0:1619a6b826d7 | 150 | doPost(uri, dataOut, pDataIn); |
Hello1024 | 0:1619a6b826d7 | 151 | return HTTP_PROCESSING; |
Hello1024 | 0:1619a6b826d7 | 152 | } |
Hello1024 | 0:1619a6b826d7 | 153 | |
Hello1024 | 0:1619a6b826d7 | 154 | ///Executes a GET Request (non blocking) |
Hello1024 | 0:1619a6b826d7 | 155 | /** |
Hello1024 | 0:1619a6b826d7 | 156 | Executes a GET request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 157 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 158 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 159 | The function returns immediately and calls the previously set callback on completion or error |
Hello1024 | 0:1619a6b826d7 | 160 | */ |
Hello1024 | 0:1619a6b826d7 | 161 | void doGet(const char* uri, HTTPData* pDataIn); |
Hello1024 | 0:1619a6b826d7 | 162 | |
Hello1024 | 0:1619a6b826d7 | 163 | ///Executes a POST Request (non blocking) |
Hello1024 | 0:1619a6b826d7 | 164 | /** |
Hello1024 | 0:1619a6b826d7 | 165 | Executes a POST request on the URI uri |
Hello1024 | 0:1619a6b826d7 | 166 | @param uri : URI on which to execute the request |
Hello1024 | 0:1619a6b826d7 | 167 | @param dataOut : a HTTPData instance that contains the data that will be posted |
Hello1024 | 0:1619a6b826d7 | 168 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
Hello1024 | 0:1619a6b826d7 | 169 | @param pMethod : callback function |
Hello1024 | 0:1619a6b826d7 | 170 | The function returns immediately and calls the previously set callback on completion or error |
Hello1024 | 0:1619a6b826d7 | 171 | */ |
Hello1024 | 0:1619a6b826d7 | 172 | void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); |
Hello1024 | 0:1619a6b826d7 | 173 | |
Hello1024 | 0:1619a6b826d7 | 174 | ///Setups the result callback |
Hello1024 | 0:1619a6b826d7 | 175 | /** |
Hello1024 | 0:1619a6b826d7 | 176 | @param pMethod : callback function |
Hello1024 | 0:1619a6b826d7 | 177 | */ |
Hello1024 | 0:1619a6b826d7 | 178 | void setOnResult( void (*pMethod)(HTTPResult) ); |
Hello1024 | 0:1619a6b826d7 | 179 | |
Hello1024 | 0:1619a6b826d7 | 180 | ///Setups the result callback |
Hello1024 | 0:1619a6b826d7 | 181 | /** |
Hello1024 | 0:1619a6b826d7 | 182 | @param pItem : instance of class on which to execute the callback method |
Hello1024 | 0:1619a6b826d7 | 183 | @param pMethod : callback method |
Hello1024 | 0:1619a6b826d7 | 184 | */ |
Hello1024 | 0:1619a6b826d7 | 185 | class CDummy; |
Hello1024 | 0:1619a6b826d7 | 186 | template<class T> |
Hello1024 | 0:1619a6b826d7 | 187 | void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) ) |
Hello1024 | 0:1619a6b826d7 | 188 | { |
Hello1024 | 0:1619a6b826d7 | 189 | m_pCb = NULL; |
Hello1024 | 0:1619a6b826d7 | 190 | m_pCbItem = (CDummy*) pItem; |
Hello1024 | 0:1619a6b826d7 | 191 | m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod; |
Hello1024 | 0:1619a6b826d7 | 192 | } |
Hello1024 | 0:1619a6b826d7 | 193 | |
Hello1024 | 0:1619a6b826d7 | 194 | ///Setups timeout |
Hello1024 | 0:1619a6b826d7 | 195 | /** |
Hello1024 | 0:1619a6b826d7 | 196 | @param ms : time of connection inactivity in ms after which the request should timeout |
Hello1024 | 0:1619a6b826d7 | 197 | */ |
Hello1024 | 0:1619a6b826d7 | 198 | void setTimeout(int ms); |
Hello1024 | 0:1619a6b826d7 | 199 | |
Hello1024 | 0:1619a6b826d7 | 200 | virtual void poll(); //Called by NetServices |
Hello1024 | 0:1619a6b826d7 | 201 | |
Hello1024 | 0:1619a6b826d7 | 202 | ///Gets last request's HTTP response code |
Hello1024 | 0:1619a6b826d7 | 203 | /** |
Hello1024 | 0:1619a6b826d7 | 204 | @return The HTTP response code of the last request |
Hello1024 | 0:1619a6b826d7 | 205 | */ |
Hello1024 | 0:1619a6b826d7 | 206 | int getHTTPResponseCode(); |
Hello1024 | 0:1619a6b826d7 | 207 | |
Hello1024 | 0:1619a6b826d7 | 208 | ///Sets a specific request header |
Hello1024 | 0:1619a6b826d7 | 209 | void setRequestHeader(const string& header, const string& value); |
Hello1024 | 0:1619a6b826d7 | 210 | |
Hello1024 | 0:1619a6b826d7 | 211 | ///Gets a response header |
Hello1024 | 0:1619a6b826d7 | 212 | string& getResponseHeader(const string& header); |
Hello1024 | 0:1619a6b826d7 | 213 | |
Hello1024 | 0:1619a6b826d7 | 214 | ///Clears request headers |
Hello1024 | 0:1619a6b826d7 | 215 | void resetRequestHeaders(); |
Hello1024 | 0:1619a6b826d7 | 216 | |
Hello1024 | 0:1619a6b826d7 | 217 | ///Setups a proxy server to be used for requests |
Hello1024 | 0:1619a6b826d7 | 218 | /** |
Hello1024 | 0:1619a6b826d7 | 219 | @param proxy_url : HTTP proxy string (e.g. proxy.mycompany.com:3380) |
Hello1024 | 0:1619a6b826d7 | 220 | port 8080 will be used if not specified |
Hello1024 | 0:1619a6b826d7 | 221 | pass NULL to disable |
Hello1024 | 0:1619a6b826d7 | 222 | */ |
Hello1024 | 0:1619a6b826d7 | 223 | void setProxy(const char* proxy_url); |
Hello1024 | 0:1619a6b826d7 | 224 | |
Hello1024 | 0:1619a6b826d7 | 225 | |
Hello1024 | 0:1619a6b826d7 | 226 | protected: |
Hello1024 | 0:1619a6b826d7 | 227 | void resetTimeout(); |
Hello1024 | 0:1619a6b826d7 | 228 | |
Hello1024 | 0:1619a6b826d7 | 229 | void init(); |
Hello1024 | 0:1619a6b826d7 | 230 | void close(); |
Hello1024 | 0:1619a6b826d7 | 231 | |
Hello1024 | 0:1619a6b826d7 | 232 | void setup(const char* uri, HTTPData* pDataOut, HTTPData* pDataIn); //Setup request, make DNS Req if necessary |
Hello1024 | 0:1619a6b826d7 | 233 | void connect(); //Start Connection |
Hello1024 | 0:1619a6b826d7 | 234 | |
Hello1024 | 0:1619a6b826d7 | 235 | int tryRead(); //Read data and try to feed output |
Hello1024 | 0:1619a6b826d7 | 236 | void readData(); //Data has been read |
Hello1024 | 0:1619a6b826d7 | 237 | void writeData(); //Data has been written & buf is free |
Hello1024 | 0:1619a6b826d7 | 238 | |
Hello1024 | 0:1619a6b826d7 | 239 | void onTCPSocketEvent(TCPSocketEvent e); |
Hello1024 | 0:1619a6b826d7 | 240 | void onDNSReply(DNSReply r); |
Hello1024 | 0:1619a6b826d7 | 241 | void onResult(HTTPResult r); //Called when exchange completed or on failure |
Hello1024 | 0:1619a6b826d7 | 242 | void onTimeout(); //Connection has timed out |
Hello1024 | 0:1619a6b826d7 | 243 | |
Hello1024 | 0:1619a6b826d7 | 244 | private: |
Hello1024 | 0:1619a6b826d7 | 245 | HTTPResult blockingProcess(); //Called in blocking mode, calls Net::poll() until return code is available |
Hello1024 | 0:1619a6b826d7 | 246 | |
Hello1024 | 0:1619a6b826d7 | 247 | bool readHeaders(); //Called first when receiving data |
Hello1024 | 0:1619a6b826d7 | 248 | bool writeHeaders(); //Called to create req |
Hello1024 | 0:1619a6b826d7 | 249 | int readLine(char* str, int maxLen, bool* pIncomplete = NULL); |
Hello1024 | 0:1619a6b826d7 | 250 | |
Hello1024 | 0:1619a6b826d7 | 251 | enum HTTP_METH |
Hello1024 | 0:1619a6b826d7 | 252 | { |
Hello1024 | 0:1619a6b826d7 | 253 | HTTP_GET, |
Hello1024 | 0:1619a6b826d7 | 254 | HTTP_POST, |
Hello1024 | 0:1619a6b826d7 | 255 | HTTP_HEAD |
Hello1024 | 0:1619a6b826d7 | 256 | }; |
Hello1024 | 0:1619a6b826d7 | 257 | |
Hello1024 | 0:1619a6b826d7 | 258 | HTTP_METH m_meth; |
Hello1024 | 0:1619a6b826d7 | 259 | |
Hello1024 | 0:1619a6b826d7 | 260 | CDummy* m_pCbItem; |
Hello1024 | 0:1619a6b826d7 | 261 | void (CDummy::*m_pCbMeth)(HTTPResult); |
Hello1024 | 0:1619a6b826d7 | 262 | |
Hello1024 | 0:1619a6b826d7 | 263 | void (*m_pCb)(HTTPResult); |
Hello1024 | 0:1619a6b826d7 | 264 | |
Hello1024 | 0:1619a6b826d7 | 265 | TCPSocket* m_pTCPSocket; |
Hello1024 | 0:1619a6b826d7 | 266 | map<string, string> m_reqHeaders; |
Hello1024 | 0:1619a6b826d7 | 267 | map<string, string> m_respHeaders; |
Hello1024 | 0:1619a6b826d7 | 268 | |
Hello1024 | 0:1619a6b826d7 | 269 | Timer m_watchdog; |
Hello1024 | 0:1619a6b826d7 | 270 | int m_timeout; |
Hello1024 | 0:1619a6b826d7 | 271 | |
Hello1024 | 0:1619a6b826d7 | 272 | DNSRequest* m_pDnsReq; |
Hello1024 | 0:1619a6b826d7 | 273 | |
Hello1024 | 0:1619a6b826d7 | 274 | Host m_server; |
Hello1024 | 0:1619a6b826d7 | 275 | string m_path; |
Hello1024 | 0:1619a6b826d7 | 276 | |
Hello1024 | 0:1619a6b826d7 | 277 | bool m_closed; |
Hello1024 | 0:1619a6b826d7 | 278 | bool m_proxy; // m_server is a proxy server |
Hello1024 | 0:1619a6b826d7 | 279 | |
Hello1024 | 0:1619a6b826d7 | 280 | |
Hello1024 | 0:1619a6b826d7 | 281 | enum HTTPStep |
Hello1024 | 0:1619a6b826d7 | 282 | { |
Hello1024 | 0:1619a6b826d7 | 283 | // HTTP_INIT, |
Hello1024 | 0:1619a6b826d7 | 284 | HTTP_WRITE_HEADERS, |
Hello1024 | 0:1619a6b826d7 | 285 | HTTP_WRITE_DATA, |
Hello1024 | 0:1619a6b826d7 | 286 | HTTP_READ_HEADERS, |
Hello1024 | 0:1619a6b826d7 | 287 | HTTP_READ_DATA, |
Hello1024 | 0:1619a6b826d7 | 288 | HTTP_READ_DATA_INCOMPLETE, |
Hello1024 | 0:1619a6b826d7 | 289 | HTTP_DONE, |
Hello1024 | 0:1619a6b826d7 | 290 | HTTP_CLOSED |
Hello1024 | 0:1619a6b826d7 | 291 | }; |
Hello1024 | 0:1619a6b826d7 | 292 | |
Hello1024 | 0:1619a6b826d7 | 293 | HTTPStep m_state; |
Hello1024 | 0:1619a6b826d7 | 294 | |
Hello1024 | 0:1619a6b826d7 | 295 | HTTPData* m_pDataOut; |
Hello1024 | 0:1619a6b826d7 | 296 | HTTPData* m_pDataIn; |
Hello1024 | 0:1619a6b826d7 | 297 | |
Hello1024 | 0:1619a6b826d7 | 298 | bool m_dataChunked; //Data is encoded as chunks |
Hello1024 | 0:1619a6b826d7 | 299 | int m_dataPos; //Position in data |
Hello1024 | 0:1619a6b826d7 | 300 | int m_dataLen; //Data length |
Hello1024 | 0:1619a6b826d7 | 301 | char* m_buf; |
Hello1024 | 0:1619a6b826d7 | 302 | char* m_pBufRemaining; //Remaining |
Hello1024 | 0:1619a6b826d7 | 303 | int m_bufRemainingLen; //Data length in m_pBufRemaining |
Hello1024 | 0:1619a6b826d7 | 304 | |
Hello1024 | 0:1619a6b826d7 | 305 | int m_httpResponseCode; |
Hello1024 | 0:1619a6b826d7 | 306 | |
Hello1024 | 0:1619a6b826d7 | 307 | HTTPResult m_blockingResult; //Result if blocking mode |
Hello1024 | 0:1619a6b826d7 | 308 | |
Hello1024 | 0:1619a6b826d7 | 309 | }; |
Hello1024 | 0:1619a6b826d7 | 310 | |
Hello1024 | 0:1619a6b826d7 | 311 | //Including data containers here for more convenience |
Hello1024 | 0:1619a6b826d7 | 312 | #include "data/HTTPFile.h" |
Hello1024 | 0:1619a6b826d7 | 313 | #include "data/HTTPStream.h" |
Hello1024 | 0:1619a6b826d7 | 314 | #include "data/HTTPText.h" |
Hello1024 | 0:1619a6b826d7 | 315 | #include "data/HTTPMap.h" |
Hello1024 | 0:1619a6b826d7 | 316 | |
Hello1024 | 0:1619a6b826d7 | 317 | #endif |