1
#pragma once
2

            
3
#include "envoy/http/header_map.h"
4

            
5
#include "absl/strings/string_view.h"
6

            
7
namespace Envoy {
8
namespace Http {
9

            
10
/**
11
 * Path helper extracted from chromium project.
12
 */
13
class PathUtil {
14
public:
15
  // Returns true if the normalization succeeds.
16
  // If it is successful, the path header will be updated with the normalized path.
17
  // Requires the Path header be present.
18
  static bool canonicalPath(RequestHeaderMap& headers);
19
  // Merges two or more adjacent slashes in path part of URI into one.
20
  // Requires the Path header be present.
21
  static void mergeSlashes(RequestHeaderMap& headers);
22

            
23
  enum class UnescapeSlashesResult {
24
    // No escaped slash sequences were found and URL path has not been modified.
25
    NotFound = 0,
26
    // Escaped slash sequences were found and URL path has been modified.
27
    FoundAndUnescaped = 1,
28
  };
29
  // Unescape %2F, %2f, %5C and %5c sequences.
30
  // Requires the Path header be present.
31
  // Returns the result of unescaping slashes.
32
  static UnescapeSlashesResult unescapeSlashes(RequestHeaderMap& headers);
33
  // Removes the query and/or fragment string (if present) from the input path.
34
  // For example, this function returns "/data" for the input path "/data?param=value#fragment".
35
  static absl::string_view removeQueryAndFragment(const absl::string_view path);
36
};
37

            
38
} // namespace Http
39
} // namespace Envoy