| 17 | SimpleTimer HttpClient::cleanUpTimer; |
| 18 | |
| 19 | bool HttpClient::send(HttpRequest* request) |
| 20 | { |
| 21 | String cacheKey = getCacheKey(request->uri); |
| 22 | |
| 23 | HttpClientConnection* connection = nullptr; |
| 24 | |
| 25 | int i = httpConnectionPool.indexOf(cacheKey); |
| 26 | if(i >= 0) { |
| 27 | // Check existing connection |
| 28 | connection = httpConnectionPool.valueAt(i); |
| 29 | } |
| 30 | |
| 31 | if(connection == nullptr) { |
| 32 | debug_d("Creating new HttpClientConnection"); |
| 33 | connection = new HttpClientConnection(); |
| 34 | if(connection == nullptr) { |
| 35 | debug_e("Cannot send request. Out of memory"); |
| 36 | // Out of memory |
| 37 | delete request; |
| 38 | return false; |
| 39 | } |
| 40 | httpConnectionPool[cacheKey] = connection; |
| 41 | } |
| 42 | |
| 43 | if(!cleanUpTimer.isStarted()) { |
| 44 | cleanUpTimer.initializeMs<60000>(HttpClient::cleanInactive).start(); // run every minute |
| 45 | } |
| 46 | return connection->send(request); |
| 47 | } |
| 48 | |
| 49 | bool HttpClient::downloadFile(const Url& url, const String& saveFileName, RequestCompletedDelegate requestComplete) |
| 50 | { |