/proc/self/cwd/source/server/api_listener_impl.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "source/server/api_listener_impl.h" |
2 | | |
3 | | #include "envoy/config/listener/v3/listener.pb.h" |
4 | | #include "envoy/http/api_listener.h" |
5 | | #include "envoy/stats/scope.h" |
6 | | |
7 | | #include "source/common/http/conn_manager_impl.h" |
8 | | #include "source/common/network/resolver_impl.h" |
9 | | #include "source/common/protobuf/utility.h" |
10 | | #include "source/extensions/filters/network/http_connection_manager/config.h" |
11 | | |
12 | | namespace Envoy { |
13 | | namespace Server { |
14 | | |
15 | 12 | bool isQuic(const envoy::config::listener::v3::Listener& config) { |
16 | 12 | return config.has_udp_listener_config() && config.udp_listener_config().has_quic_options(); |
17 | 12 | } |
18 | | |
19 | | ApiListenerImplBase::ApiListenerImplBase(const envoy::config::listener::v3::Listener& config, |
20 | | Server::Instance& server, const std::string& name) |
21 | | : config_(config), name_(name), |
22 | | address_(Network::Address::resolveProtoAddress(config.address())), |
23 | | global_scope_(server.stats().createScope("")), |
24 | | listener_scope_(server.stats().createScope(fmt::format("listener.api.{}.", name_))), |
25 | 12 | factory_context_(server, config_, *this, *global_scope_, *listener_scope_, isQuic(config)) {} |
26 | | |
27 | | void ApiListenerImplBase::SyntheticReadCallbacks::SyntheticConnection::raiseConnectionEvent( |
28 | 0 | Network::ConnectionEvent event) { |
29 | 0 | for (Network::ConnectionCallbacks* callback : callbacks_) { |
30 | 0 | callback->onEvent(event); |
31 | 0 | } |
32 | 0 | } |
33 | | |
34 | 0 | HttpApiListener::ApiListenerWrapper::~ApiListenerWrapper() { |
35 | | // The Http::ConnectionManagerImpl is a callback target for the read_callback_.connection_. By |
36 | | // raising connection closure, Http::ConnectionManagerImpl::onEvent is fired. In that case the |
37 | | // Http::ConnectionManagerImpl will reset any ActiveStreams it has. |
38 | 0 | read_callbacks_.connection_.raiseConnectionEvent(Network::ConnectionEvent::RemoteClose); |
39 | 0 | } |
40 | | |
41 | | Http::RequestDecoderHandlePtr |
42 | | HttpApiListener::ApiListenerWrapper::newStreamHandle(Http::ResponseEncoder& response_encoder, |
43 | 0 | bool is_internally_created) { |
44 | 0 | return http_connection_manager_->newStreamHandle(response_encoder, is_internally_created); |
45 | 0 | } |
46 | | |
47 | | HttpApiListener::HttpApiListener(const envoy::config::listener::v3::Listener& config, |
48 | | Server::Instance& server, const std::string& name) |
49 | 12 | : ApiListenerImplBase(config, server, name) { |
50 | 12 | if (config.api_listener().api_listener().type_url() == |
51 | 12 | absl::StrCat( |
52 | 12 | "type.googleapis.com/", |
53 | 12 | createReflectableMessage(envoy::extensions::filters::network::http_connection_manager:: |
54 | 12 | v3::EnvoyMobileHttpConnectionManager::default_instance()) |
55 | 12 | ->GetDescriptor() |
56 | 12 | ->full_name())) { |
57 | 0 | auto typed_config = MessageUtil::anyConvertAndValidate< |
58 | 0 | envoy::extensions::filters::network::http_connection_manager::v3:: |
59 | 0 | EnvoyMobileHttpConnectionManager>(config.api_listener().api_listener(), |
60 | 0 | factory_context_.messageValidationVisitor()); |
61 | |
|
62 | 0 | http_connection_manager_factory_ = Envoy::Extensions::NetworkFilters::HttpConnectionManager:: |
63 | 0 | HttpConnectionManagerFactory::createHttpConnectionManagerFactoryFromProto( |
64 | 0 | typed_config.config(), factory_context_, false); |
65 | 12 | } else { |
66 | 12 | auto typed_config = MessageUtil::anyConvertAndValidate< |
67 | 12 | envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager>( |
68 | 12 | config.api_listener().api_listener(), factory_context_.messageValidationVisitor()); |
69 | | |
70 | 12 | http_connection_manager_factory_ = |
71 | 12 | Envoy::Extensions::NetworkFilters::HttpConnectionManager::HttpConnectionManagerFactory:: |
72 | 12 | createHttpConnectionManagerFactoryFromProto(typed_config, factory_context_, true); |
73 | 12 | } |
74 | 12 | } |
75 | | |
76 | 0 | Http::ApiListenerPtr HttpApiListener::createHttpApiListener(Event::Dispatcher& dispatcher) { |
77 | 0 | return std::make_unique<ApiListenerWrapper>(*this, dispatcher); |
78 | 0 | } |
79 | | |
80 | | } // namespace Server |
81 | | } // namespace Envoy |