1 // Copyright 2015 The Weave Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef LIBWEAVE_EXAMPLES_PROVIDER_CURL_HTTP_CLIENT_H_ 6 #define LIBWEAVE_EXAMPLES_PROVIDER_CURL_HTTP_CLIENT_H_ 7 8 #include <future> 9 #include <string> 10 #include <utility> 11 12 #include <base/memory/weak_ptr.h> 13 #include <weave/provider/http_client.h> 14 15 namespace weave { 16 17 namespace provider { 18 class TaskRunner; 19 } 20 21 namespace examples { 22 23 // Basic implementation of weave::HttpClient using libcurl. Should be used in 24 // production code as it's blocking and does not validate server certificates. 25 class CurlHttpClient : public provider::HttpClient { 26 public: 27 explicit CurlHttpClient(provider::TaskRunner* task_runner); 28 29 void SendRequest(Method method, 30 const std::string& url, 31 const Headers& headers, 32 const std::string& data, 33 const SendRequestCallback& callback) override; 34 35 private: 36 void CheckTasks(); 37 38 std::vector< 39 std::pair<std::future<std::pair<std::unique_ptr<Response>, ErrorPtr>>, 40 SendRequestCallback>> 41 pending_tasks_; 42 provider::TaskRunner* task_runner_{nullptr}; 43 44 base::WeakPtrFactory<CurlHttpClient> weak_ptr_factory_{this}; 45 }; 46 47 } // namespace examples 48 } // namespace weave 49 50 #endif // LIBWEAVE_EXAMPLES_PROVIDER_CURL_HTTP_CLIENT_H_ 51