#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/http/http_util.h"
#include <algorithm>
#include <string>
#include <string_view>
#include "base/check_op.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "net/base/features.h"
#include "net/base/mime_util.h"
#include "net/base/parse_number.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
namespace net {
namespace {
template <typename ConstIterator>
void TrimLWSImplementation(ConstIterator* begin, ConstIterator* end) { … }
class AcceptLanguageBuilder { … };
std::string GetBaseLanguageCode(const std::string& language_code) { … }
}
std::string HttpUtil::GenerateRequestLine(std::string_view method,
GURL url,
bool is_for_get_to_http_proxy) { … }
std::string HttpUtil::SpecForRequest(const GURL& url) { … }
void HttpUtil::ParseContentType(const std::string& content_type_str,
std::string* mime_type,
std::string* charset,
bool* had_charset,
std::string* boundary) { … }
bool HttpUtil::ParseRangeHeader(const std::string& ranges_specifier,
std::vector<HttpByteRange>* ranges) { … }
bool HttpUtil::ParseContentRangeHeaderFor206(
std::string_view content_range_spec,
int64_t* first_byte_position,
int64_t* last_byte_position,
int64_t* instance_length) { … }
bool HttpUtil::ParseRetryAfterHeader(const std::string& retry_after_string,
base::Time now,
base::TimeDelta* retry_after) { … }
std::string HttpUtil::TimeFormatHTTP(base::Time time) { … }
namespace {
const char* const kForbiddenHeaderFields[] = …;
const char* const kForbiddenHeaderFieldsWithForbiddenMethod[] = …;
const char* const kForbiddenMethods[] = …;
}
bool HttpUtil::IsMethodSafe(std::string_view method) { … }
bool HttpUtil::IsMethodIdempotent(std::string_view method) { … }
bool HttpUtil::IsSafeHeader(std::string_view name, std::string_view value) { … }
bool HttpUtil::IsValidHeaderName(std::string_view name) { … }
bool HttpUtil::IsValidHeaderValue(std::string_view value) { … }
bool HttpUtil::IsNonCoalescingHeader(std::string_view name) { … }
void HttpUtil::TrimLWS(std::string::const_iterator* begin,
std::string::const_iterator* end) { … }
std::string_view HttpUtil::TrimLWS(std::string_view string) { … }
bool HttpUtil::IsTokenChar(char c) { … }
bool HttpUtil::IsToken(std::string_view string) { … }
bool HttpUtil::IsParmName(std::string_view str) { … }
namespace {
bool IsQuote(char c) { … }
bool UnquoteImpl(std::string_view str, bool strict_quotes, std::string* out) { … }
}
std::string HttpUtil::Unquote(std::string_view str) { … }
bool HttpUtil::StrictUnquote(std::string_view str, std::string* out) { … }
std::string HttpUtil::Quote(std::string_view str) { … }
size_t HttpUtil::LocateStartOfStatusLine(const char* buf, size_t buf_len) { … }
static size_t LocateEndOfHeadersHelper(const char* buf,
size_t buf_len,
size_t i,
bool accept_empty_header_list) { … }
size_t HttpUtil::LocateEndOfAdditionalHeaders(const char* buf,
size_t buf_len,
size_t i) { … }
size_t HttpUtil::LocateEndOfHeaders(const char* buf, size_t buf_len, size_t i) { … }
static bool IsLineSegmentContinuable(std::string_view line) { … }
static size_t FindStatusLineEnd(std::string_view str) { … }
static std::string_view RemoveLeadingNonLWS(std::string_view str) { … }
std::string HttpUtil::AssembleRawHeaders(std::string_view input) { … }
std::string HttpUtil::ConvertHeadersBackToHTTPResponse(const std::string& str) { … }
std::string HttpUtil::ExpandLanguageList(const std::string& language_prefs) { … }
std::string HttpUtil::GenerateAcceptLanguageHeader(
const std::string& raw_language_list) { … }
bool HttpUtil::HasStrongValidators(HttpVersion version,
const std::string& etag_header,
const std::string& last_modified_header,
const std::string& date_header) { … }
bool HttpUtil::HasValidators(HttpVersion version,
const std::string& etag_header,
const std::string& last_modified_header) { … }
enum { … };
std::vector<int> HttpUtil::GetStatusCodesForHistogram() { … }
int HttpUtil::MapStatusCodeForHistogram(int code) { … }
HttpUtil::HeadersIterator::HeadersIterator(
std::string::const_iterator headers_begin,
std::string::const_iterator headers_end,
const std::string& line_delimiter)
: … { … }
HttpUtil::HeadersIterator::~HeadersIterator() = default;
bool HttpUtil::HeadersIterator::GetNext() { … }
bool HttpUtil::HeadersIterator::AdvanceTo(const char* name) { … }
HttpUtil::ValuesIterator::ValuesIterator(
std::string::const_iterator values_begin,
std::string::const_iterator values_end,
char delimiter,
bool ignore_empty_values)
: … { … }
HttpUtil::ValuesIterator::ValuesIterator(const ValuesIterator& other) = default;
HttpUtil::ValuesIterator::~ValuesIterator() = default;
bool HttpUtil::ValuesIterator::GetNext() { … }
HttpUtil::NameValuePairsIterator::NameValuePairsIterator(
std::string::const_iterator begin,
std::string::const_iterator end,
char delimiter,
Values optional_values,
Quotes strict_quotes)
: … { … }
HttpUtil::NameValuePairsIterator::NameValuePairsIterator(
std::string::const_iterator begin,
std::string::const_iterator end,
char delimiter)
: … { … }
HttpUtil::NameValuePairsIterator::NameValuePairsIterator(
const NameValuePairsIterator& other) = default;
HttpUtil::NameValuePairsIterator::~NameValuePairsIterator() = default;
bool HttpUtil::NameValuePairsIterator::GetNext() { … }
bool HttpUtil::ParseAcceptEncoding(const std::string& accept_encoding,
std::set<std::string>* allowed_encodings) { … }
bool HttpUtil::ParseContentEncoding(const std::string& content_encoding,
std::set<std::string>* used_encodings) { … }
bool HttpUtil::HeadersContainMultipleCopiesOfField(
const HttpResponseHeaders& headers,
const std::string& field_name) { … }
}