1
#pragma once
2

            
3
#include "envoy/extensions/http/original_ip_detection/custom_header/v3/custom_header.pb.h"
4
#include "envoy/http/codes.h"
5
#include "envoy/http/original_ip_detection.h"
6

            
7
namespace Envoy {
8
namespace Extensions {
9
namespace Http {
10
namespace OriginalIPDetection {
11
namespace CustomHeader {
12

            
13
/**
14
 * Custom header IP detection extension.
15
 */
16
class CustomHeaderIPDetection : public Envoy::Http::OriginalIPDetection {
17
public:
18
  CustomHeaderIPDetection(
19
      const envoy::extensions::http::original_ip_detection::custom_header::v3::CustomHeaderConfig&
20
          config);
21
  CustomHeaderIPDetection(
22
      const std::string& header_name,
23
      absl::optional<Envoy::Http::OriginalIPRejectRequestOptions> reject_options = absl::nullopt);
24

            
25
  Envoy::Http::OriginalIPDetectionResult
26
  detect(Envoy::Http::OriginalIPDetectionParams& params) override;
27

            
28
private:
29
4
  static Envoy::Http::Code toErrorCode(uint64_t status) {
30
4
    const auto code = static_cast<Envoy::Http::Code>(status);
31
4
    if (code >= Envoy::Http::Code::BadRequest &&
32
4
        code <= Envoy::Http::Code::NetworkAuthenticationRequired) {
33
3
      return code;
34
3
    }
35
1
    return Envoy::Http::Code::Forbidden;
36
4
  }
37

            
38
  Envoy::Http::LowerCaseString header_name_;
39
  bool allow_trusted_address_checks_{false};
40
  absl::optional<Envoy::Http::OriginalIPRejectRequestOptions> reject_options_{absl::nullopt};
41
};
42

            
43
} // namespace CustomHeader
44
} // namespace OriginalIPDetection
45
} // namespace Http
46
} // namespace Extensions
47
} // namespace Envoy