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