PathUtil::UnescapeSlashesResult PathUtil::unescapeSlashes(RequestHeaderMap& headers) {
  ASSERT(headers.Path());
  const auto original_path = headers.getPathValue();
  const auto original_length = original_path.length();
  // Only operate on path component in URL.
  const absl::string_view::size_type query_start = original_path.find('?');
  const absl::string_view path = original_path.substr(0, query_start);
  if (path.find('%') == absl::string_view::npos) {
    return UnescapeSlashesResult::NotFound;
  }
  const absl::string_view query = absl::ClippedSubstr(original_path, query_start);

  // TODO(yanavlasov): optimize this by adding case insensitive matcher
  std::string decoded_path{path};
  unescapeInPath(decoded_path, "%2F", "/");
  unescapeInPath(decoded_path, "%2f", "/");
  unescapeInPath(decoded_path, "%5C", "\\");
  unescapeInPath(decoded_path, "%5c", "\\");
  headers.setPath(absl::StrCat(decoded_path, query));
  // Path length will not match if there were unescaped %2f or %5c
  return headers.getPathValue().length() != original_length
             ? UnescapeSlashesResult::FoundAndUnescaped
             : UnescapeSlashesResult::NotFound;
}
PathUtil::UnescapeSlashesResult PathUtil::unescapeSlashes(RequestHeaderMap& headers) {
  ASSERT(headers.Path());
  const auto original_path = headers.getPathValue();
  const auto original_length = original_path.length();
   
  const absl::string_view::size_type query_start = original_path.find('?');
  const absl::string_view path = original_path.substr(0, query_start);
  if (path.find('%') == absl::string_view::npos) {
    return UnescapeSlashesResult::NotFound;
  }
  const absl::string_view query = absl::ClippedSubstr(original_path, query_start);

   
  std::string decoded_path{path};
  unescapeInPath(decoded_path, "%2F", "/");
  unescapeInPath(decoded_path, "%2f", "/");
  unescapeInPath(decoded_path, "%5C", "\\");
  unescapeInPath(decoded_path, "%5c", "\\");
  headers.setPath(absl::StrCat(decoded_path, query));
   
  return headers.getPathValue().length() != original_length
             ? UnescapeSlashesResult::FoundAndUnescaped
             : UnescapeSlashesResult::NotFound;
}