http_server_request_info.cc 1.4 KB

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