1
#include "source/extensions/http/stateful_session/header/header.h"
2

            
3
namespace Envoy {
4
namespace Extensions {
5
namespace Http {
6
namespace StatefulSession {
7
namespace Header {
8

            
9
bool HeaderBasedSessionStateFactory::SessionStateImpl::onUpdate(
10
11
    absl::string_view host_address, Envoy::Http::ResponseHeaderMap& headers) {
11
11
  const bool host_changed =
12
11
      !upstream_address_.has_value() || host_address != upstream_address_.value();
13
11
  if (host_changed) {
14
5
    const std::string encoded_address =
15
5
        Envoy::Base64::encode(host_address.data(), host_address.length());
16
5
    headers.setCopy(factory_.getHeaderName(), encoded_address);
17
5
  }
18
11
  return host_changed;
19
11
}
20

            
21
HeaderBasedSessionStateFactory::HeaderBasedSessionStateFactory(
22
    const HeaderBasedSessionStateProto& config)
23
9
    : name_(config.name()) {
24
9
  if (config.name().empty()) {
25
1
    throw EnvoyException("Header name cannot be empty for header based stateful sessions");
26
1
  }
27
9
}
28

            
29
} // namespace Header
30
} // namespace StatefulSession
31
} // namespace Http
32
} // namespace Extensions
33
} // namespace Envoy