link_header_util.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2016 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. #ifndef COMPONENTS_LINK_HEADER_UTIL_LINK_HEADER_UTIL_H_
  5. #define COMPONENTS_LINK_HEADER_UTIL_LINK_HEADER_UTIL_H_
  6. #include <string>
  7. #include <unordered_map>
  8. #include <vector>
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace link_header_util {
  11. using StringIteratorPair =
  12. std::pair<std::string::const_iterator, std::string::const_iterator>;
  13. // Split a Link: header in its individual values. A single Link: header can
  14. // contain multiple values, which are comma separated. This method splits the
  15. // entire string into iterator pairs for the individual link values.
  16. // This is very similar to what net::HttpUtil::ValuesIterator does, except it
  17. // takes the special syntax of <> enclosed URLs into account.
  18. std::vector<StringIteratorPair> SplitLinkHeader(const std::string& header);
  19. // Parse an individual link header in its URL and parameters. `begin` and `end`
  20. // indicate the string to parse. If it is successfully parsed as a link header
  21. // value this method returns true, sets `url` to the URL part of the link header
  22. // value and adds the parameters from the link header value to `params`. All
  23. // keys of `params` are lower cased.
  24. // If any error occurs parsing, this returns false (but might have also modified
  25. // |url| and/or |params|).
  26. bool ParseLinkHeaderValue(
  27. std::string::const_iterator begin,
  28. std::string::const_iterator end,
  29. std::string* url,
  30. std::unordered_map<std::string, absl::optional<std::string>>* params);
  31. } // namespace link_header_util
  32. #endif // COMPONENTS_LINK_HEADER_UTIL_LINK_HEADER_UTIL_H_