1 // Copyright 2014 The Chromium OS 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 LIBBRILLO_BRILLO_HTTP_HTTP_CONNECTION_FAKE_H_ 6 #define LIBBRILLO_BRILLO_HTTP_HTTP_CONNECTION_FAKE_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include <base/macros.h> 13 #include <brillo/http/http_connection.h> 14 #include <brillo/http/http_transport_fake.h> 15 16 namespace brillo { 17 namespace http { 18 namespace fake { 19 20 // This is a fake implementation of http::Connection for unit testing. 21 class Connection : public http::Connection { 22 public: 23 Connection(const std::string& url, 24 const std::string& method, 25 const std::shared_ptr<http::Transport>& transport); 26 ~Connection() override; 27 28 // Overrides from http::Connection. 29 // See http_connection.h for description of these methods. 30 bool SendHeaders(const HeaderList& headers, brillo::ErrorPtr* error) override; 31 bool SetRequestData(StreamPtr stream, brillo::ErrorPtr* error) override; SetResponseData(StreamPtr)32 void SetResponseData(StreamPtr /* stream */) override {} 33 bool FinishRequest(brillo::ErrorPtr* error) override; 34 RequestID FinishRequestAsync(const SuccessCallback& success_callback, 35 const ErrorCallback& error_callback) override; 36 37 int GetResponseStatusCode() const override; 38 std::string GetResponseStatusText() const override; 39 std::string GetProtocolVersion() const override; 40 std::string GetResponseHeader(const std::string& header_name) const override; 41 StreamPtr ExtractDataStream(brillo::ErrorPtr* error) override; 42 43 private: 44 // A helper method for FinishRequestAsync() implementation. 45 void FinishRequestAsyncHelper(const SuccessCallback& success_callback, 46 const ErrorCallback& error_callback); 47 48 // Request and response objects passed to the user-provided request handler 49 // callback. The request object contains all the request information. 50 // The response object is the server response that is created by 51 // the handler in response to the request. 52 ServerRequest request_; 53 ServerResponse response_; 54 55 DISALLOW_COPY_AND_ASSIGN(Connection); 56 }; 57 58 } // namespace fake 59 } // namespace http 60 } // namespace brillo 61 62 #endif // LIBBRILLO_BRILLO_HTTP_HTTP_CONNECTION_FAKE_H_ 63