Buffet: Move buffet over to platform2 from src/platform/buffet.
This change also open-sources buffet. The only change in this CL
is the removal of the Makefile and addition of the buffet.gyp file.
BUG=chromium:355180
TEST=USE=buffet emerge-gizmo platform2
Change-Id: Ibf8d3ac3f38313f82a9c07d79932b6f30130f9c5
diff --git a/buffet/http_utils.h b/buffet/http_utils.h
new file mode 100644
index 0000000..0fff847
--- /dev/null
+++ b/buffet/http_utils.h
@@ -0,0 +1,79 @@
+// 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_UTILS_H_
+#define BUFFET_HTTP_UTILS_H_
+
+#include "buffet/http_request.h"
+
+namespace base { class Value; }
+
+namespace chromeos {
+namespace http {
+
+////////////////////////////////////////////////////////////////////////////////
+// The following are simple utility helper functions for common HTTP operations
+// that use http::Request object behind the scenes and set it up accordingly.
+//
+// For more advanced functionality you need to use Request/Response objects
+// directly.
+////////////////////////////////////////////////////////////////////////////////
+
+// Performs a simple GET request and returns the data as a string.
+std::string GetAsString(char const* url);
+
+// Performs a GET request. Success status, returned data and additional
+// information (such as returned HTTP headers) can be obtained from
+// the returned Response object.
+std::unique_ptr<Response> Get(char const* url);
+
+// Performs a HEAD request. Success status and additional
+// information (such as returned HTTP headers) can be obtained from
+// the returned Response object.
+std::unique_ptr<Response> Head(char const* url);
+
+// Performs a POST request with binary data. Success status, returned data
+// and additional information (such as returned HTTP headers) can be obtained
+// from the returned Response object.
+// If data MIME type is not specified, "application/octet-stream" is assumed
+std::unique_ptr<Response> PostBinary(char const* url,
+ void const* data,
+ size_t data_size,
+ char const* mime_type);
+
+inline std::unique_ptr<Response> PostBinary(char const* url,
+ void const* data,
+ size_t data_size) {
+ return PostBinary(url, data, data_size, nullptr);
+}
+
+// Performs a POST request with text data. Success status, returned data
+// and additional information (such as returned HTTP headers) can be obtained
+// from the returned Response object.
+// If data MIME type is not specified, "application/x-www-form-urlencoded"
+// is assumed
+std::unique_ptr<Response> PostText(char const* url,
+ char const* data,
+ char const* mime_type);
+
+inline std::unique_ptr<Response> PostText(char const* url, char const* data) {
+ return PostText(url, data, nullptr);
+}
+
+// Performs a POST request with JSON data. Success status, returned data
+// and additional information (such as returned HTTP headers) can be obtained
+// from the returned Response object. If a JSON response is expected,
+// use ParseJsonResponse() method on the returned Response object.
+std::unique_ptr<Response> PostJson(char const* url, base::Value const* json);
+
+// Given an http::Response object, parse the body data into Json object.
+// Returns null if failed. Optional |error_message| can be passed in to
+// get the extended error information as to why the parse failed.
+std::unique_ptr<base::Value> ParseJsonResponse(Response const* response,
+ std::string* error_message);
+
+} // namespace http
+} // namespace chromeos
+
+#endif // BUFFET_HTTP_UTILS_H_