2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/common/net/http_header_utils.h"
|
|
|
|
|
2019-10-14 13:32:38 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "base/strings/string_util.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/http/http_response_headers.h"
|
|
|
|
#include "net/http/http_util.h"
|
|
|
|
|
|
|
|
using net::HttpResponseHeaders;
|
|
|
|
|
|
|
|
namespace HttpHeaderUtils {
|
|
|
|
|
|
|
|
std::string GenerateHeaders(const HeaderMap& map) {
|
|
|
|
std::string headers;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
for (HeaderMap::const_iterator header = map.begin(); header != map.end();
|
2012-04-03 03:34:16 +02:00
|
|
|
++header) {
|
|
|
|
const CefString& key = header->first;
|
|
|
|
const CefString& value = header->second;
|
|
|
|
|
|
|
|
if (!key.empty()) {
|
|
|
|
// Delimit with "\r\n".
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!headers.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
headers += "\r\n";
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
headers += std::string(key) + ": " + std::string(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParseHeaders(const std::string& header_str, HeaderMap& map) {
|
|
|
|
// Parse the request header values
|
2017-05-17 11:29:28 +02:00
|
|
|
for (net::HttpUtil::HeadersIterator i(header_str.begin(), header_str.end(),
|
2018-07-02 19:11:49 +02:00
|
|
|
"\n\r");
|
2017-05-17 11:29:28 +02:00
|
|
|
i.GetNext();) {
|
2012-04-03 03:34:16 +02:00
|
|
|
map.insert(std::make_pair(i.name(), i.values()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-14 13:32:38 +02:00
|
|
|
void MakeASCIILower(std::string* str) {
|
|
|
|
std::transform(str->begin(), str->end(), str->begin(), ::tolower);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeaderMap::iterator FindHeaderInMap(const std::string& nameLower,
|
|
|
|
HeaderMap& map) {
|
|
|
|
for (auto it = map.begin(); it != map.end(); ++it) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(it->first.ToString(), nameLower)) {
|
2019-10-14 13:32:38 +02:00
|
|
|
return it;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-10-14 13:32:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return map.end();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // namespace HttpHeaderUtils
|