1
#include "source/common/http/http1/settings.h"
2

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

            
5
#include "source/common/common/matchers.h"
6
#include "source/common/config/utility.h"
7
#include "source/common/runtime/runtime_features.h"
8

            
9
namespace Envoy {
10
namespace Http {
11
namespace Http1 {
12

            
13
Http1Settings parseHttp1Settings(const envoy::config::core::v3::Http1ProtocolOptions& config,
14
                                 Server::Configuration::CommonFactoryContext& context,
15
28168
                                 ProtobufMessage::ValidationVisitor& validation_visitor) {
16
28168
  Http1Settings ret;
17
28168
  ret.allow_absolute_url_ = PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, allow_absolute_url, true);
18
28168
  ret.accept_http_10_ = config.accept_http_10();
19
28168
  ret.send_fully_qualified_url_ = config.send_fully_qualified_url();
20
28168
  ret.default_host_for_http_10_ = config.default_host_for_http_10();
21
28168
  ret.enable_trailers_ = config.enable_trailers();
22
28168
  ret.allow_chunked_length_ = config.allow_chunked_length();
23

            
24
28168
  if (!config.ignore_http_11_upgrade().empty()) {
25
1
    std::vector<Matchers::StringMatcherPtr> matchers;
26
1
    matchers.reserve(config.ignore_http_11_upgrade_size());
27
1
    for (const auto& matcher : config.ignore_http_11_upgrade()) {
28
1
      matchers.emplace_back(std::make_unique<Envoy::Matchers::StringMatcherImpl>(matcher, context));
29
1
    }
30
1
    ret.ignore_upgrade_matchers_ =
31
1
        std::make_shared<const std::vector<Matchers::StringMatcherPtr>>(std::move(matchers));
32
1
  }
33

            
34
28168
  if (config.header_key_format().has_proper_case_words()) {
35
4
    ret.header_key_format_ = Http1Settings::HeaderKeyFormat::ProperCase;
36
28166
  } else if (config.header_key_format().has_stateful_formatter()) {
37
6
    auto& factory =
38
6
        Config::Utility::getAndCheckFactory<Envoy::Http::StatefulHeaderKeyFormatterFactoryConfig>(
39
6
            config.header_key_format().stateful_formatter());
40
6
    auto header_formatter_config = Envoy::Config::Utility::translateAnyToFactoryConfig(
41
6
        config.header_key_format().stateful_formatter().typed_config(), validation_visitor,
42
6
        factory);
43
6
    ret.header_key_format_ = Http1Settings::HeaderKeyFormat::StatefulFormatter;
44
6
    ret.stateful_header_key_formatter_ = factory.createFromProto(*header_formatter_config);
45
6
  }
46

            
47
28168
  ret.allow_custom_methods_ = config.allow_custom_methods();
48

            
49
28168
  return ret;
50
28168
}
51

            
52
Http1Settings parseHttp1Settings(const envoy::config::core::v3::Http1ProtocolOptions& config,
53
                                 Server::Configuration::CommonFactoryContext& context,
54
                                 ProtobufMessage::ValidationVisitor& validation_visitor,
55
                                 const Protobuf::BoolValue& hcm_stream_error,
56
9982
                                 bool validate_scheme) {
57
9982
  Http1Settings ret = parseHttp1Settings(config, context, validation_visitor);
58
9982
  ret.validate_scheme_ = validate_scheme;
59

            
60
9982
  if (config.has_override_stream_error_on_invalid_http_message()) {
61
    // override_stream_error_on_invalid_http_message, if set, takes precedence over any HCM
62
    // stream_error_on_invalid_http_message
63
32
    ret.stream_error_on_invalid_http_message_ =
64
32
        config.override_stream_error_on_invalid_http_message().value();
65
9950
  } else {
66
    // fallback to HCM value
67
9950
    ret.stream_error_on_invalid_http_message_ = hcm_stream_error.value();
68
9950
  }
69

            
70
9982
  return ret;
71
9982
}
72

            
73
} // namespace Http1
74
} // namespace Http
75
} // namespace Envoy