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 "base/strings/string_split.h"
8 #include "base/strings/string_util.h"
9
10 namespace net {
11
12 HttpServerRequestInfo::HttpServerRequestInfo() = default;
13
14 HttpServerRequestInfo::HttpServerRequestInfo(
15 const HttpServerRequestInfo& other) = default;
16
17 HttpServerRequestInfo::~HttpServerRequestInfo() = default;
18
GetHeaderValue(const std::string & header_name) const19 std::string HttpServerRequestInfo::GetHeaderValue(
20 const std::string& header_name) const {
21 DCHECK_EQ(base::ToLowerASCII(header_name), header_name);
22 HttpServerRequestInfo::HeadersMap::const_iterator it =
23 headers.find(header_name);
24 if (it != headers.end())
25 return it->second;
26 return std::string();
27 }
28
HasHeaderValue(const std::string & header_name,const std::string & header_value) const29 bool HttpServerRequestInfo::HasHeaderValue(
30 const std::string& header_name,
31 const std::string& header_value) const {
32 DCHECK_EQ(base::ToLowerASCII(header_value), header_value);
33 std::string complete_value = base::ToLowerASCII(GetHeaderValue(header_name));
34
35 for (base::StringPiece cur :
36 base::SplitStringPiece(complete_value, ",", base::KEEP_WHITESPACE,
37 base::SPLIT_WANT_NONEMPTY)) {
38 if (base::TrimString(cur, " \t", base::TRIM_ALL) == header_value)
39 return true;
40 }
41 return false;
42 }
43
44 } // namespace net
45