buffet: reworked http transport to prepare for unit testing
Changed the way HTTP transport classes are implemented. Now
the Transport class is a very simple factory class that just
creates an appropriate instance of http::Connection object.
http::Connection is a thin layer wrapper around underlying
transport library, such as libcurl.
Also, the Transport class is now stateless and can be used
to initiate multiple HTTP connections.
Majority of HTTP processing is done in http::Request and
http::Response classes which are not dependent on the underlying
transport.
The HTTP utility functions now take the Transport class as
a parameter to facilitate unit tesing.
Also added a stub http_utils_unittest.cc to be populated
with actual tests when the fake HTTP transport is implemented.
BUG=chromium:364733
TEST=Unit tests pass.
Change-Id: If506854d274f725bbc2d6f765f19344d8697a239
Reviewed-on: https://chromium-review.googlesource.com/196153
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/http_transport.h b/buffet/http_transport.h
new file mode 100644
index 0000000..752dcbe
--- /dev/null
+++ b/buffet/http_transport.h
@@ -0,0 +1,51 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BUFFET_HTTP_TRANSPORT_H_
+#define BUFFET_HTTP_TRANSPORT_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include <base/basictypes.h>
+
+namespace chromeos {
+namespace http {
+
+typedef std::vector<std::pair<std::string, std::string>> HeaderList;
+
+class Request;
+class Connection;
+
+///////////////////////////////////////////////////////////////////////////////
+// Transport is a base class for specific implementation of HTTP communication.
+// This class (and its underlying implementation) is used by http::Request and
+// http::Response classes to provide HTTP functionality to the clients.
+///////////////////////////////////////////////////////////////////////////////
+class Transport {
+ public:
+ Transport() = default;
+ virtual ~Transport() = default;
+
+ // Creates a connection object and initializes it with the specified data.
+ // |transport| is a shared pointer to this transport object instance,
+ // used to maintain the object alive as long as the connection exists.
+ virtual std::unique_ptr<Connection> CreateConnection(
+ std::shared_ptr<Transport> transport,
+ const std::string& url,
+ const std::string& method,
+ const HeaderList& headers,
+ const std::string& user_agent,
+ const std::string& referer,
+ std::string* error_msg) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Transport);
+};
+
+} // namespace http
+} // namespace chromeos
+
+#endif // BUFFET_HTTP_TRANSPORT_H_