1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/server/http_server_request_info.h"
6
7 #include <string_view>
8
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h"
11
12 namespace net {
13
14 HttpServerRequestInfo::HttpServerRequestInfo() = default;
15
16 HttpServerRequestInfo::HttpServerRequestInfo(
17 const HttpServerRequestInfo& other) = default;
18
19 HttpServerRequestInfo::~HttpServerRequestInfo() = default;
20
GetHeaderValue(const std::string & header_name) const21 std::string HttpServerRequestInfo::GetHeaderValue(
22 const std::string& header_name) const {
23 DCHECK_EQ(base::ToLowerASCII(header_name), header_name);
24 HttpServerRequestInfo::HeadersMap::const_iterator it =
25 headers.find(header_name);
26 if (it != headers.end())
27 return it->second;
28 return std::string();
29 }
30
HasHeaderValue(const std::string & header_name,const std::string & header_value) const31 bool HttpServerRequestInfo::HasHeaderValue(
32 const std::string& header_name,
33 const std::string& header_value) const {
34 DCHECK_EQ(base::ToLowerASCII(header_value), header_value);
35 std::string complete_value = base::ToLowerASCII(GetHeaderValue(header_name));
36
37 for (std::string_view cur :
38 base::SplitStringPiece(complete_value, ",", base::KEEP_WHITESPACE,
39 base::SPLIT_WANT_NONEMPTY)) {
40 if (base::TrimString(cur, " \t", base::TRIM_ALL) == header_value)
41 return true;
42 }
43 return false;
44 }
45
46 } // namespace net
47