/proc/self/cwd/source/server/admin/admin_filter.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <functional> |
4 | | #include <list> |
5 | | |
6 | | #include "envoy/http/filter.h" |
7 | | #include "envoy/server/admin.h" |
8 | | |
9 | | #include "source/common/buffer/buffer_impl.h" |
10 | | #include "source/common/common/logger.h" |
11 | | #include "source/common/http/codes.h" |
12 | | #include "source/common/http/header_map_impl.h" |
13 | | #include "source/extensions/filters/http/common/pass_through_filter.h" |
14 | | |
15 | | #include "absl/strings/string_view.h" |
16 | | |
17 | | namespace Envoy { |
18 | | namespace Server { |
19 | | |
20 | | /** |
21 | | * A terminal HTTP filter that implements server admin functionality. |
22 | | */ |
23 | | class AdminFilter : public Http::PassThroughFilter, |
24 | | public AdminStream, |
25 | | Logger::Loggable<Logger::Id::admin> { |
26 | | public: |
27 | | using AdminServerCallbackFunction = std::function<Http::Code( |
28 | | absl::string_view path_and_query, Http::ResponseHeaderMap& response_headers, |
29 | | Buffer::OwnedImpl& response, AdminFilter& filter)>; |
30 | | |
31 | | AdminFilter(Admin::GenRequestFn admin_handler_func); |
32 | | |
33 | | // Http::StreamFilterBase |
34 | | // Handlers relying on the reference should use addOnDestroyCallback() |
35 | | // to add a callback that will notify them when the reference is no |
36 | | // longer valid. |
37 | | void onDestroy() override; |
38 | | |
39 | | // Http::StreamDecoderFilter |
40 | | Http::FilterHeadersStatus decodeHeaders(Http::RequestHeaderMap& headers, |
41 | | bool end_stream) override; |
42 | | Http::FilterDataStatus decodeData(Buffer::Instance& data, bool end_stream) override; |
43 | | Http::FilterTrailersStatus decodeTrailers(Http::RequestTrailerMap& trailers) override; |
44 | | |
45 | | // AdminStream |
46 | 0 | void setEndStreamOnComplete(bool end_stream) override { end_stream_on_complete_ = end_stream; } |
47 | | void addOnDestroyCallback(std::function<void()> cb) override; |
48 | | Http::StreamDecoderFilterCallbacks& getDecoderFilterCallbacks() const override; |
49 | | const Buffer::Instance* getRequestBody() const override; |
50 | | const Http::RequestHeaderMap& getRequestHeaders() const override; |
51 | 0 | Http::Http1StreamEncoderOptionsOptRef http1StreamEncoderOptions() override { |
52 | 0 | return encoder_callbacks_->http1StreamEncoderOptions(); |
53 | 0 | } |
54 | | Http::Utility::QueryParams queryParams() const override; |
55 | | |
56 | | private: |
57 | | /** |
58 | | * Called when an admin request has been completely received. |
59 | | */ |
60 | | void onComplete(); |
61 | | Admin::GenRequestFn admin_handler_fn_; |
62 | | Http::RequestHeaderMap* request_headers_{}; |
63 | | std::list<std::function<void()>> on_destroy_callbacks_; |
64 | | bool end_stream_on_complete_ = true; |
65 | | }; |
66 | | |
67 | | } // namespace Server |
68 | | } // namespace Envoy |