1
#pragma once
2

            
3
#include "envoy/config/core/v3/http_service.pb.h"
4
#include "envoy/formatter/substitution_formatter_base.h"
5
#include "envoy/http/header_map.h"
6
#include "envoy/server/factory_context.h"
7

            
8
#include "source/common/http/headers.h"
9
#include "source/common/stream_info/stream_info_impl.h"
10

            
11
namespace Envoy {
12
namespace Http {
13

            
14
/**
15
 * Parses and applies request_headers_to_add from an HTTP service configuration.
16
 *
17
 * Separates headers into static (plain string value) and formatted (substitution
18
 * formatter) groups. Static headers are evaluated once at construction time.
19
 * Formatted headers are re-evaluated on each apply() call, so that
20
 * runtime updates such as SDS secret rotation are reflected in outgoing requests.
21
 */
22
class HttpServiceHeadersApplicator {
23
public:
24
  HttpServiceHeadersApplicator(const envoy::config::core::v3::HttpService& http_service,
25
                               Server::Configuration::ServerFactoryContext& server_context,
26
                               absl::Status& creation_status);
27

            
28
  /**
29
   * Apply all parsed headers to the outgoing request message.
30
   */
31
  void apply(RequestHeaderMap& headers) const;
32

            
33
private:
34
  std::vector<std::pair<const LowerCaseString, std::string>> static_headers_;
35
  std::vector<std::pair<const LowerCaseString, Formatter::FormatterPtr>> formatted_headers_;
36

            
37
  // A `StreamInfo` is required, but in this context we don't have one, so create an empty one.
38
  // This allows formatters that don't require any stream info to succeed, such as extensions that
39
  // load data externally for API keys and similar.
40
  const StreamInfo::StreamInfoImpl stream_info_;
41
};
42

            
43
} // namespace Http
44
} // namespace Envoy