libchromeos: Move mime_utils from Buffet to libchromeos
BUG=chromium:405714
TEST=USE=buffet ./build_packages
Change-Id: I4e0bf9600aedda9a9ac913a1234ab1b20da72777
Reviewed-on: https://chromium-review.googlesource.com/213364
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/buffet.gyp b/buffet/buffet.gyp
index bbbe8dc..b95637f 100644
--- a/buffet/buffet.gyp
+++ b/buffet/buffet.gyp
@@ -34,7 +34,6 @@
'http_transport_curl.cc',
'http_utils.cc',
'manager.cc',
- 'mime_utils.cc',
'storage_impls.cc',
],
},
@@ -86,7 +85,6 @@
'http_connection_fake.cc',
'http_transport_fake.cc',
'http_utils_unittest.cc',
- 'mime_utils_unittest.cc',
],
},
],
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc
index 9e59d78..3e09f30 100644
--- a/buffet/device_registration_info.cc
+++ b/buffet/device_registration_info.cc
@@ -11,6 +11,7 @@
#include <base/json/json_writer.h>
#include <base/values.h>
#include <chromeos/data_encoding.h>
+#include <chromeos/mime_utils.h>
#include <chromeos/string_utils.h>
#include <chromeos/url_utils.h>
@@ -19,7 +20,6 @@
#include "buffet/device_registration_storage_keys.h"
#include "buffet/http_transport_curl.h"
#include "buffet/http_utils.h"
-#include "buffet/mime_utils.h"
#include "buffet/storage_impls.h"
const char buffet::kErrorDomainOAuth2[] = "oauth2";
diff --git a/buffet/device_registration_info_unittest.cc b/buffet/device_registration_info_unittest.cc
index f883802..268e56e 100644
--- a/buffet/device_registration_info_unittest.cc
+++ b/buffet/device_registration_info_unittest.cc
@@ -5,6 +5,7 @@
#include <base/json/json_reader.h>
#include <base/values.h>
#include <chromeos/bind_lambda.h>
+#include <chromeos/mime_utils.h>
#include <gtest/gtest.h>
#include "buffet/commands/command_manager.h"
@@ -13,7 +14,6 @@
#include "buffet/device_registration_storage_keys.h"
#include "buffet/http_request.h"
#include "buffet/http_transport_fake.h"
-#include "buffet/mime_utils.h"
#include "buffet/storage_impls.h"
using namespace buffet; // NOLINT(build/namespaces)
diff --git a/buffet/http_connection_fake.cc b/buffet/http_connection_fake.cc
index 1cc58e0..6cfdde3 100644
--- a/buffet/http_connection_fake.cc
+++ b/buffet/http_connection_fake.cc
@@ -5,10 +5,10 @@
#include "buffet/http_connection_fake.h"
#include <base/logging.h>
+#include <chromeos/mime_utils.h>
#include <chromeos/string_utils.h>
#include "buffet/http_request.h"
-#include "buffet/mime_utils.h"
namespace buffet {
namespace http {
@@ -48,7 +48,7 @@
<< " request at " << request_.GetURL();
response_.ReplyText(status_code::NotFound,
"<html><body>Not found</body></html>",
- mime::text::kHtml);
+ chromeos::mime::text::kHtml);
} else {
handler.Run(request_, &response_);
}
diff --git a/buffet/http_request.cc b/buffet/http_request.cc
index 1c32efe..d818b07 100644
--- a/buffet/http_request.cc
+++ b/buffet/http_request.cc
@@ -5,12 +5,12 @@
#include "buffet/http_request.h"
#include <base/logging.h>
+#include <chromeos/mime_utils.h>
#include <chromeos/string_utils.h>
#include "buffet/http_connection_curl.h"
#include "buffet/http_transport_curl.h"
#include "buffet/map_utils.h"
-#include "buffet/mime_utils.h"
namespace buffet {
namespace http {
diff --git a/buffet/http_transport_fake.cc b/buffet/http_transport_fake.cc
index abf822b..9aefbe3 100644
--- a/buffet/http_transport_fake.cc
+++ b/buffet/http_transport_fake.cc
@@ -10,12 +10,12 @@
#include <base/json/json_writer.h>
#include <base/logging.h>
#include <chromeos/bind_lambda.h>
+#include <chromeos/mime_utils.h>
#include <chromeos/string_utils.h>
#include <chromeos/url_utils.h>
#include "buffet/http_connection_fake.h"
#include "buffet/http_request.h"
-#include "buffet/mime_utils.h"
namespace buffet {
@@ -113,8 +113,9 @@
std::unique_ptr<base::DictionaryValue>
ServerRequestResponseBase::GetDataAsJson() const {
- if (mime::RemoveParameters(GetHeader(request_header::kContentType)) ==
- mime::application::kJson) {
+ if (chromeos::mime::RemoveParameters(
+ GetHeader(request_header::kContentType)) ==
+ chromeos::mime::application::kJson) {
auto value = base::JSONReader::Read(GetDataAsString());
if (value) {
base::DictionaryValue* dict = nullptr;
@@ -152,9 +153,9 @@
std::string ServerRequest::GetFormField(const std::string& field_name) const {
if (!form_fields_parsed_) {
- std::string mime_type = mime::RemoveParameters(
+ std::string mime_type = chromeos::mime::RemoveParameters(
GetHeader(request_header::kContentType));
- if (mime_type == mime::application::kWwwFormUrlEncoded &&
+ if (mime_type == chromeos::mime::application::kWwwFormUrlEncoded &&
!GetData().empty()) {
auto fields = chromeos::data_encoding::WebParamsDecode(GetDataAsString());
form_fields_.insert(fields.begin(), fields.end());
@@ -187,9 +188,10 @@
base::JSONWriter::WriteWithOptions(json,
base::JSONWriter::OPTIONS_PRETTY_PRINT,
&text);
- std::string mime_type = mime::AppendParameter(mime::application::kJson,
- mime::parameters::kCharset,
- "utf-8");
+ std::string mime_type = chromeos::mime::AppendParameter(
+ chromeos::mime::application::kJson,
+ chromeos::mime::parameters::kCharset,
+ "utf-8");
ReplyText(status_code, text, mime_type.c_str());
}
diff --git a/buffet/http_utils.cc b/buffet/http_utils.cc
index 439acab..d61d176 100644
--- a/buffet/http_utils.cc
+++ b/buffet/http_utils.cc
@@ -11,8 +11,10 @@
#include <base/values.h>
#include <chromeos/data_encoding.h>
#include <chromeos/error_codes.h>
+#include <chromeos/mime_utils.h>
-#include "buffet/mime_utils.h"
+using chromeos::mime::AppendParameter;
+using chromeos::mime::RemoveParameters;
namespace buffet {
namespace http {
@@ -47,7 +49,7 @@
std::shared_ptr<Transport> transport,
chromeos::ErrorPtr* error) {
if (mime_type == nullptr) {
- mime_type = mime::application::kWwwFormUrlEncoded;
+ mime_type = chromeos::mime::application::kWwwFormUrlEncoded;
}
return PostBinary(url, data, strlen(data), mime_type, headers, transport,
@@ -66,7 +68,7 @@
request.AddHeaders(headers);
if (data_size > 0) {
if (mime_type == nullptr) {
- mime_type = mime::application::kOctet_stream;
+ mime_type = chromeos::mime::application::kOctet_stream;
}
request.SetContentType(mime_type);
if (!request.AddRequestBody(data, data_size, error))
@@ -91,7 +93,7 @@
chromeos::ErrorPtr* error) {
std::string encoded_data = chromeos::data_encoding::WebParamsEncode(data);
return PostBinary(url, encoded_data.c_str(), encoded_data.size(),
- mime::application::kWwwFormUrlEncoded,
+ chromeos::mime::application::kWwwFormUrlEncoded,
headers, transport, error);
}
@@ -104,9 +106,9 @@
std::string data;
if (json)
base::JSONWriter::Write(json, &data);
- std::string mime_type = mime::AppendParameter(mime::application::kJson,
- mime::parameters::kCharset,
- "utf-8");
+ std::string mime_type = AppendParameter(chromeos::mime::application::kJson,
+ chromeos::mime::parameters::kCharset,
+ "utf-8");
return PostBinary(url, data.c_str(), data.size(),
mime_type.c_str(), headers, transport, error);
}
@@ -119,9 +121,9 @@
std::string data;
if (json)
base::JSONWriter::Write(json, &data);
- std::string mime_type = mime::AppendParameter(mime::application::kJson,
- mime::parameters::kCharset,
- "utf-8");
+ std::string mime_type = AppendParameter(chromeos::mime::application::kJson,
+ chromeos::mime::parameters::kCharset,
+ "utf-8");
return SendRequest(request_type::kPatch, url, data.c_str(), data.size(),
mime_type.c_str(), headers, transport, error);
}
@@ -136,9 +138,9 @@
// Make sure we have a correct content type. Do not try to parse
// binary files, or HTML output. Limit to application/json and text/plain.
- auto content_type = mime::RemoveParameters(response->GetContentType());
- if (content_type != mime::application::kJson &&
- content_type != mime::text::kPlain) {
+ auto content_type = RemoveParameters(response->GetContentType());
+ if (content_type != chromeos::mime::application::kJson &&
+ content_type != chromeos::mime::text::kPlain) {
chromeos::Error::AddTo(error, chromeos::errors::json::kDomain,
"non_json_content_type",
"Unexpected response content type: " + content_type);
diff --git a/buffet/http_utils_unittest.cc b/buffet/http_utils_unittest.cc
index 4bb8383..8f40ad7 100644
--- a/buffet/http_utils_unittest.cc
+++ b/buffet/http_utils_unittest.cc
@@ -7,13 +7,13 @@
#include <base/values.h>
#include <chromeos/bind_lambda.h>
+#include <chromeos/mime_utils.h>
#include <chromeos/string_utils.h>
#include <chromeos/url_utils.h>
#include <gtest/gtest.h>
#include "buffet/http_transport_fake.h"
#include "buffet/http_utils.h"
-#include "buffet/mime_utils.h"
using namespace buffet; // NOLINT(build/namespaces)
using namespace buffet::http; // NOLINT(build/namespaces)
@@ -33,7 +33,8 @@
// Returns the request method as a plain text response.
static void EchoMethodHandler(const fake::ServerRequest& request,
fake::ServerResponse* response) {
- response->ReplyText(status_code::Ok, request.GetMethod(), mime::text::kPlain);
+ response->ReplyText(status_code::Ok, request.GetMethod(),
+ chromeos::mime::text::kPlain);
}
///////////////////////////////////////////////////////////////////////////////
@@ -46,10 +47,11 @@
std::vector<unsigned char> custom_data{0xFF, 0x00, 0x80, 0x40, 0xC0, 0x7F};
auto response = http::SendRequest(request_type::kPost, kEchoUrl,
custom_data.data(), custom_data.size(),
- mime::application::kOctet_stream,
+ chromeos::mime::application::kOctet_stream,
HeaderList(), transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::application::kOctet_stream, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::application::kOctet_stream,
+ response->GetContentType());
EXPECT_EQ(custom_data.size(), response->GetData().size());
EXPECT_EQ(custom_data, response->GetData());
}
@@ -64,10 +66,10 @@
// Check the correct HTTP method used.
auto response = http::SendRequest(request_type::kPost, kMethodEchoUrl,
custom_data.data(), custom_data.size(),
- mime::application::kOctet_stream,
+ chromeos::mime::application::kOctet_stream,
HeaderList(), transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::text::kPlain, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::text::kPlain, response->GetContentType());
EXPECT_EQ(request_type::kPost, response->GetDataAsString());
}
@@ -79,7 +81,7 @@
nullptr, 0, nullptr,
HeaderList(), transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::text::kPlain, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::text::kPlain, response->GetContentType());
EXPECT_EQ(request_type::kGet, response->GetDataAsString());
}
@@ -91,7 +93,7 @@
nullptr, 0, nullptr,
HeaderList(), transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::text::kPlain, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::text::kPlain, response->GetContentType());
EXPECT_EQ(request_type::kPut, response->GetDataAsString());
}
@@ -123,13 +125,13 @@
base::Bind(JsonEchoHandler));
auto response = http::SendRequest(
request_type::kPost, json_echo_url, "abcd", 4,
- mime::application::kOctet_stream, {
+ chromeos::mime::application::kOctet_stream, {
{request_header::kCookie, "flavor=vanilla"},
{request_header::kIfMatch, "*"},
}, transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::application::kJson,
- mime::RemoveParameters(response->GetContentType()));
+ EXPECT_EQ(chromeos::mime::application::kJson,
+ chromeos::mime::RemoveParameters(response->GetContentType()));
auto json = ParseJsonResponse(response.get(), nullptr, nullptr);
std::string value;
EXPECT_TRUE(json->GetString("method", &value));
@@ -139,7 +141,7 @@
EXPECT_TRUE(json->GetString("header.Cookie", &value));
EXPECT_EQ("flavor=vanilla", value);
EXPECT_TRUE(json->GetString("header.Content-Type", &value));
- EXPECT_EQ(mime::application::kOctet_stream, value);
+ EXPECT_EQ(chromeos::mime::application::kOctet_stream, value);
EXPECT_TRUE(json->GetString("header.Content-Length", &value));
EXPECT_EQ("4", value);
EXPECT_TRUE(json->GetString("header.If-Match", &value));
@@ -156,7 +158,7 @@
EXPECT_EQ("0", request.GetHeader(request_header::kContentLength));
EXPECT_EQ("", request.GetHeader(request_header::kContentType));
response->ReplyText(status_code::Ok, request.GetFormField("test"),
- mime::text::kPlain);
+ chromeos::mime::text::kPlain);
};
std::shared_ptr<fake::Transport> transport(new fake::Transport);
@@ -166,7 +168,7 @@
// Make sure Get/GetAsString actually do the GET request
auto response = http::Get(kMethodEchoUrl, transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::text::kPlain, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::text::kPlain, response->GetContentType());
EXPECT_EQ(request_type::kGet, response->GetDataAsString());
EXPECT_EQ(request_type::kGet,
http::GetAsString(kMethodEchoUrl, transport, nullptr));
@@ -184,7 +186,7 @@
EXPECT_EQ("0", request.GetHeader(request_header::kContentLength));
EXPECT_EQ("", request.GetHeader(request_header::kContentType));
response->ReplyText(status_code::Ok, "blah",
- mime::text::kPlain);
+ chromeos::mime::text::kPlain);
};
std::shared_ptr<fake::Transport> transport(new fake::Transport);
@@ -192,7 +194,7 @@
auto response = http::Head(kFakeUrl, transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::text::kPlain, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::text::kPlain, response->GetContentType());
EXPECT_EQ("", response->GetDataAsString()); // Must not have actual body.
EXPECT_EQ("4", response->GetHeader(request_header::kContentLength));
}
@@ -202,7 +204,7 @@
fake::ServerResponse* response) {
EXPECT_EQ(request_type::kPost, request.GetMethod());
EXPECT_EQ("256", request.GetHeader(request_header::kContentLength));
- EXPECT_EQ(mime::application::kOctet_stream,
+ EXPECT_EQ(chromeos::mime::application::kOctet_stream,
request.GetHeader(request_header::kContentType));
const auto& data = request.GetData();
EXPECT_EQ(256, data.size());
@@ -210,7 +212,7 @@
// Sum up all the bytes.
int sum = std::accumulate(data.begin(), data.end(), 0);
EXPECT_EQ(32640, sum); // sum(i, i => [0, 255]) = 32640.
- response->ReplyText(status_code::Ok, "", mime::text::kPlain);
+ response->ReplyText(status_code::Ok, "", chromeos::mime::text::kPlain);
};
std::shared_ptr<fake::Transport> transport(new fake::Transport);
@@ -232,19 +234,20 @@
EXPECT_EQ(request_type::kPost, request.GetMethod());
EXPECT_EQ(fake_data.size(),
std::stoul(request.GetHeader(request_header::kContentLength)));
- EXPECT_EQ(mime::text::kPlain,
+ EXPECT_EQ(chromeos::mime::text::kPlain,
request.GetHeader(request_header::kContentType));
response->ReplyText(status_code::Ok, request.GetDataAsString(),
- mime::text::kPlain);
+ chromeos::mime::text::kPlain);
};
std::shared_ptr<fake::Transport> transport(new fake::Transport);
transport->AddHandler(kFakeUrl, request_type::kPost, base::Bind(PostHandler));
auto response = http::PostText(kFakeUrl, fake_data.c_str(),
- mime::text::kPlain, transport, nullptr);
+ chromeos::mime::text::kPlain,
+ transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::text::kPlain, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::text::kPlain, response->GetContentType());
EXPECT_EQ(fake_data, response->GetDataAsString());
}
@@ -258,16 +261,17 @@
{"field", "field value"},
}, transport, nullptr);
EXPECT_TRUE(response->IsSuccessful());
- EXPECT_EQ(mime::application::kWwwFormUrlEncoded, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::application::kWwwFormUrlEncoded,
+ response->GetContentType());
EXPECT_EQ("key=value&field=field+value", response->GetDataAsString());
}
TEST(HttpUtils, PostPatchJson) {
auto JsonHandler = [](const fake::ServerRequest& request,
fake::ServerResponse* response) {
- auto mime_type = mime::RemoveParameters(
+ auto mime_type = chromeos::mime::RemoveParameters(
request.GetHeader(request_header::kContentType));
- EXPECT_EQ(mime::application::kJson, mime_type);
+ EXPECT_EQ(chromeos::mime::application::kJson, mime_type);
response->ReplyJson(status_code::Ok, {
{"method", request.GetMethod()},
{"data", request.GetDataAsString()},
@@ -328,7 +332,7 @@
// Test invalid (non-JSON) response.
auto response = http::Get("http://bad.url", transport, nullptr);
EXPECT_EQ(status_code::NotFound, response->GetStatusCode());
- EXPECT_EQ(mime::text::kHtml, response->GetContentType());
+ EXPECT_EQ(chromeos::mime::text::kHtml, response->GetContentType());
int code = 0;
auto json = http::ParseJsonResponse(response.get(), &code, nullptr);
EXPECT_EQ(nullptr, json.get());
diff --git a/buffet/mime_utils.cc b/buffet/mime_utils.cc
deleted file mode 100644
index 5747405..0000000
--- a/buffet/mime_utils.cc
+++ /dev/null
@@ -1,157 +0,0 @@
-// 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.
-
-#include "buffet/mime_utils.h"
-
-#include <algorithm>
-#include <base/strings/string_util.h>
-#include <chromeos/string_utils.h>
-
-namespace buffet {
-
-// ***************************************************************************
-// ******************************* MIME types ********************************
-// ***************************************************************************
-const char mime::types::kApplication[] = "application";
-const char mime::types::kAudio[] = "audio";
-const char mime::types::kImage[] = "image";
-const char mime::types::kMessage[] = "message";
-const char mime::types::kMultipart[] = "multipart";
-const char mime::types::kText[] = "text";
-const char mime::types::kVideo[] = "video";
-
-const char mime::parameters::kCharset[] = "charset";
-
-const char mime::image::kJpeg[] = "image/jpeg";
-const char mime::image::kPng[] = "image/png";
-const char mime::image::kBmp[] = "image/bmp";
-const char mime::image::kTiff[] = "image/tiff";
-const char mime::image::kGif[] = "image/gif";
-
-const char mime::text::kPlain[] = "text/plain";
-const char mime::text::kHtml[] = "text/html";
-const char mime::text::kXml[] = "text/xml";
-
-const char mime::application::kOctet_stream[] = "application/octet-stream";
-const char mime::application::kJson[] = "application/json";
-const char mime::application::kWwwFormUrlEncoded[] =
- "application/x-www-form-urlencoded";
-
-// ***************************************************************************
-// **************************** Utility Functions ****************************
-// ***************************************************************************
-static std::string EncodeParam(const std::string& param) {
- // If the string contains one of "tspecials" characters as
- // specified in RFC 1521, enclose it in quotes.
- if (param.find_first_of("()<>@,;:\\\"/[]?=") != std::string::npos) {
- return '"' + param + '"';
- }
- return param;
-}
-
-static std::string DecodeParam(const std::string& param) {
- if (param.size() > 1 && param.front() == '"' && param.back() == '"') {
- return param.substr(1, param.size() - 2);
- }
- return param;
-}
-
-// ***************************************************************************
-// ******************** Main MIME manipulation functions *********************
-// ***************************************************************************
-
-bool mime::Split(const std::string& mime_string,
- std::string* type, std::string* subtype,
- mime::Parameters* parameters) {
- std::vector<std::string> parts = chromeos::string_utils::Split(mime_string,
- ';');
- if (parts.empty())
- return false;
-
- if (!mime::Split(parts.front(), type, subtype))
- return false;
-
- if (parameters) {
- parameters->clear();
- parameters->reserve(parts.size() - 1);
- for (size_t i = 1; i < parts.size(); i++) {
- auto pair = chromeos::string_utils::SplitAtFirst(parts[i], '=');
- pair.second = DecodeParam(pair.second);
- parameters->push_back(pair);
- }
- }
- return true;
-}
-
-bool mime::Split(const std::string& mime_string,
- std::string* type, std::string* subtype) {
- std::string mime = mime::RemoveParameters(mime_string);
- auto types = chromeos::string_utils::SplitAtFirst(mime, '/');
-
- if (type)
- *type = types.first;
-
- if (subtype)
- *subtype = types.second;
-
- return !types.first.empty() && !types.second.empty();
-}
-
-std::string mime::Combine(const std::string& type, const std::string& subtype,
- const mime::Parameters& parameters) {
- std::vector<std::string> parts;
- parts.push_back(chromeos::string_utils::Join('/', type, subtype));
- for (const auto& pair : parameters) {
- parts.push_back(chromeos::string_utils::Join('=',
- pair.first,
- EncodeParam(pair.second)));
- }
- return chromeos::string_utils::Join("; ", parts);
-}
-
-std::string mime::GetType(const std::string& mime_string) {
- std::string mime = mime::RemoveParameters(mime_string);
- return chromeos::string_utils::SplitAtFirst(mime, '/').first;
-}
-
-std::string mime::GetSubtype(const std::string& mime_string) {
- std::string mime = mime::RemoveParameters(mime_string);
- return chromeos::string_utils::SplitAtFirst(mime, '/').second;
-}
-
-mime::Parameters mime::GetParameters(const std::string& mime_string) {
- std::string type;
- std::string subtype;
- mime::Parameters parameters;
-
- if (mime::Split(mime_string, &type, &subtype, ¶meters))
- return std::move(parameters);
-
- return mime::Parameters();
-}
-
-std::string mime::RemoveParameters(const std::string& mime_string) {
- return chromeos::string_utils::SplitAtFirst(mime_string, ';').first;
-}
-
-std::string mime::AppendParameter(const std::string& mime_string,
- const std::string& paramName,
- const std::string& paramValue) {
- std::string mime(mime_string);
- mime += "; ";
- mime += chromeos::string_utils::Join('=', paramName, EncodeParam(paramValue));
- return mime;
-}
-
-std::string mime::GetParameterValue(const std::string& mime_string,
- const std::string& paramName) {
- mime::Parameters params = mime::GetParameters(mime_string);
- for (const auto& pair : params) {
- if (base::strcasecmp(pair.first.c_str(), paramName.c_str()) == 0)
- return pair.second;
- }
- return std::string();
-}
-
-} // namespace buffet
diff --git a/buffet/mime_utils.h b/buffet/mime_utils.h
deleted file mode 100644
index 999b677..0000000
--- a/buffet/mime_utils.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// 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_MIME_UTILS_H_
-#define BUFFET_MIME_UTILS_H_
-
-#include <string>
-#include <utility>
-#include <vector>
-
-#include <base/basictypes.h>
-
-namespace buffet {
-
-namespace mime {
-
-namespace types {
- // Main MIME type categories
- extern const char kApplication[]; // application
- extern const char kAudio[]; // audio
- extern const char kImage[]; // image
- extern const char kMessage[]; // message
- extern const char kMultipart[]; // multipart
- extern const char kText[]; // test
- extern const char kVideo[]; // video
-}
-
-namespace parameters {
- // Common MIME parameters
- extern const char kCharset[]; // charset=...
-}
-
-namespace image {
- // Common image MIME types
- extern const char kJpeg[]; // image/jpeg
- extern const char kPng[]; // image/png
- extern const char kBmp[]; // image/bmp
- extern const char kTiff[]; // image/tiff
- extern const char kGif[]; // image/gif
-}
-
-namespace text {
- // Common text MIME types
- extern const char kPlain[]; // text/plain
- extern const char kHtml[]; // text/html
- extern const char kXml[]; // text/xml
-}
-
-namespace application {
- // Common application MIME types
- extern const char kOctet_stream[]; // application/octet-stream
- extern const char kJson[]; // application/json
- extern const char kWwwFormUrlEncoded[]; // application/x-www-form-urlencoded
-}
-
-typedef std::vector<std::pair<std::string, std::string>> Parameters;
-
-// Combine a MIME type, subtype and parameters into a MIME string.
-// e.g. Combine("text", "plain", {{"charset", "utf-8"}}) will give:
-// "text/plain; charset=utf-8"
-std::string Combine(const std::string& type, const std::string& subtype,
- const Parameters& parameters = {}) WARN_UNUSED_RESULT;
-
-// Splits a MIME string into type and subtype.
-// "text/plain;charset=utf-8" => ("text", "plain")
-bool Split(const std::string& mime_string,
- std::string* type, std::string* subtype);
-
-// Splits a MIME string into type, subtype, and parameters.
-// "text/plain;charset=utf-8" => ("text", "plain", {{"charset","utf-8"}})
-bool Split(const std::string& mime_string,
- std::string* type, std::string* subtype, Parameters* parameters);
-
-// Returns the MIME type from MIME string.
-// "text/plain;charset=utf-8" => "text"
-std::string GetType(const std::string& mime_string);
-
-// Returns the MIME sub-type from MIME string.
-// "text/plain;charset=utf-8" => "plain"
-std::string GetSubtype(const std::string& mime_string);
-
-// Returns the MIME parameters from MIME string.
-// "text/plain;charset=utf-8" => {{"charset","utf-8"}}
-Parameters GetParameters(const std::string& mime_string);
-
-// Removes parameters from a MIME string
-// "text/plain;charset=utf-8" => "text/plain"
-std::string RemoveParameters(const std::string& mime_string) WARN_UNUSED_RESULT;
-
-// Appends a parameter to a MIME string.
-// "text/plain" => "text/plain; charset=utf-8"
-std::string AppendParameter(const std::string& mime_string,
- const std::string& paramName,
- const std::string& paramValue) WARN_UNUSED_RESULT;
-
-// Returns the value of a parameter on a MIME string (empty string if missing).
-// ("text/plain;charset=utf-8","charset") => "utf-8"
-std::string GetParameterValue(const std::string& mime_string,
- const std::string& paramName);
-
-} // namespace mime
-} // namespace buffet
-
-#endif // BUFFET_MIME_UTILS_H_
diff --git a/buffet/mime_utils_unittest.cc b/buffet/mime_utils_unittest.cc
deleted file mode 100644
index a705dfa..0000000
--- a/buffet/mime_utils_unittest.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright (c) 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.
-
-#include "buffet/mime_utils.h"
-
-#include <gtest/gtest.h>
-
-using namespace buffet; // NOLINT(build/namespaces)
-
-TEST(MimeUtils, Combine) {
- std::string mime_string = mime::Combine(mime::types::kText, "xml");
- EXPECT_EQ(mime::text::kXml, mime_string);
- EXPECT_EQ("application/json; charset=utf-8",
- mime::Combine(mime::types::kApplication, "json",
- {{"charset", "utf-8"}}));
-}
-
-TEST(MimeUtils, Split) {
- std::string s1, s2;
- EXPECT_TRUE(mime::Split(mime::image::kJpeg, &s1, &s2));
- EXPECT_EQ(mime::types::kImage, s1);
- EXPECT_EQ("jpeg", s2);
-
- mime::Parameters parameters;
- EXPECT_TRUE(mime::Split("application/json;charset=utf-8",
- &s1, &s2, ¶meters));
- EXPECT_EQ(mime::types::kApplication, s1);
- EXPECT_EQ("json", s2);
- EXPECT_EQ(mime::application::kJson, mime::Combine(s1, s2));
- EXPECT_EQ(1, parameters.size());
- EXPECT_EQ(mime::parameters::kCharset, parameters.front().first);
- EXPECT_EQ("utf-8", parameters.front().second);
- EXPECT_EQ("application/json; charset=utf-8",
- mime::Combine(s1, s2, parameters));
-}
-
-TEST(MimeUtils, ExtractParts) {
- mime::Parameters parameters;
-
- EXPECT_EQ(mime::types::kText, mime::GetType(mime::text::kPlain));
- EXPECT_EQ("plain", mime::GetSubtype(mime::text::kPlain));
-
- parameters = mime::GetParameters("text/plain; charset=iso-8859-1;foo=bar");
- EXPECT_EQ(2, parameters.size());
- EXPECT_EQ(mime::parameters::kCharset, parameters[0].first);
- EXPECT_EQ("iso-8859-1", parameters[0].second);
- EXPECT_EQ("foo", parameters[1].first);
- EXPECT_EQ("bar", parameters[1].second);
-}
-
-TEST(MimeUtils, AppendRemoveParams) {
- std::string mime_string = mime::AppendParameter(mime::text::kXml,
- mime::parameters::kCharset,
- "utf-8");
- EXPECT_EQ("text/xml; charset=utf-8", mime_string);
- mime_string = mime::AppendParameter(mime_string, "foo", "bar");
- EXPECT_EQ("text/xml; charset=utf-8; foo=bar", mime_string);
- EXPECT_EQ("utf-8", mime::GetParameterValue(mime_string,
- mime::parameters::kCharset));
- EXPECT_EQ("bar", mime::GetParameterValue(mime_string, "foo"));
- EXPECT_EQ("", mime::GetParameterValue(mime_string, "baz"));
- mime_string = mime::RemoveParameters(mime_string);
- EXPECT_EQ(mime::text::kXml, mime_string);
-}