1 // Copyright 2021 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 #ifndef NET_THIRD_PARTY_QUICHE_OVERRIDES_QUICHE_PLATFORM_IMPL_QUICHE_URL_UTILS_IMPL_H_ 6 #define NET_THIRD_PARTY_QUICHE_OVERRIDES_QUICHE_PLATFORM_IMPL_QUICHE_URL_UTILS_IMPL_H_ 7 8 #include <optional> 9 #include <string> 10 #include <string_view> 11 12 #include "quiche/common/platform/api/quiche_export.h" 13 #include "third_party/abseil-cpp/absl/container/flat_hash_map.h" 14 #include "third_party/abseil-cpp/absl/container/flat_hash_set.h" 15 16 namespace quiche { 17 18 // Produces concrete URLs in |target| from templated ones in |uri_template|. 19 // Parameters are URL-encoded. Collects the names of any expanded variables in 20 // |vars_found|. Supports templates up to level 3 as specified in RFC 6570, 21 // though without checking for disallowed characters in variable names. Returns 22 // true if the template was parseable, false if it was malformed. 23 QUICHE_EXPORT bool ExpandURITemplateImpl( 24 const std::string& uri_template, 25 const absl::flat_hash_map<std::string, std::string>& parameters, 26 std::string* target, 27 absl::flat_hash_set<std::string>* vars_found = nullptr); 28 29 // Decodes a URL-encoded string and converts it to ASCII. If the decoded input 30 // contains non-ASCII characters, decoding fails and std::nullopt is returned. 31 QUICHE_EXPORT std::optional<std::string> AsciiUrlDecodeImpl( 32 std::string_view input); 33 34 } // namespace quiche 35 36 #endif // NET_THIRD_PARTY_QUICHE_OVERRIDES_QUICHE_PLATFORM_IMPL_QUICHE_URL_UTILS_IMPL_H_ 37