/proc/self/cwd/test/integration/integration_stream_decoder.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <cstdint> |
4 | | #include <memory> |
5 | | #include <string> |
6 | | |
7 | | #include "envoy/event/dispatcher.h" |
8 | | #include "envoy/http/codec.h" |
9 | | #include "envoy/http/header_map.h" |
10 | | #include "envoy/http/metadata_interface.h" |
11 | | |
12 | | #include "source/common/common/dump_state_utils.h" |
13 | | |
14 | | #include "test/test_common/utility.h" |
15 | | |
16 | | #include "absl/container/node_hash_map.h" |
17 | | #include "absl/strings/string_view.h" |
18 | | #include "gtest/gtest.h" |
19 | | |
20 | | namespace Envoy { |
21 | | /** |
22 | | * Stream decoder wrapper used during integration testing. |
23 | | */ |
24 | | class IntegrationStreamDecoder : public Http::ResponseDecoder, public Http::StreamCallbacks { |
25 | | public: |
26 | | IntegrationStreamDecoder(Event::Dispatcher& dispatcher); |
27 | | ~IntegrationStreamDecoder() override; |
28 | | |
29 | 0 | const std::string& body() { return body_; } |
30 | 0 | bool complete() { return saw_end_stream_; } |
31 | 0 | bool reset() { return saw_reset_; } |
32 | 0 | Http::StreamResetReason resetReason() { return reset_reason_; } |
33 | 0 | const Http::ResponseHeaderMap* informationalHeaders() { return continue_headers_.get(); } |
34 | 0 | const Http::ResponseHeaderMap& headers() { return *headers_; } |
35 | 0 | const Http::ResponseTrailerMapPtr& trailers() { return trailers_; } |
36 | 0 | const Http::MetadataMap& metadataMap() { return *metadata_map_; } |
37 | 0 | uint64_t keyCount(std::string key) { return duplicated_metadata_key_count_[key]; } |
38 | 0 | uint32_t metadataMapsDecodedCount() const { return metadata_maps_decoded_count_; } |
39 | | void waitFor1xxHeaders(); |
40 | | void waitForHeaders(); |
41 | | // This function waits until body_ has at least size bytes in it (it might have more). clearBody() |
42 | | // can be used if the previous body data is not relevant and the test wants to wait for a specific |
43 | | // amount of new data without considering the existing body size. |
44 | | void waitForBodyData(uint64_t size); |
45 | | ABSL_MUST_USE_RESULT testing::AssertionResult |
46 | | waitForEndStream(std::chrono::milliseconds timeout = TestUtility::DefaultTimeout); |
47 | | ABSL_MUST_USE_RESULT testing::AssertionResult |
48 | | waitForReset(std::chrono::milliseconds timeout = TestUtility::DefaultTimeout); |
49 | 0 | void clearBody() { body_.clear(); } |
50 | | |
51 | | // Http::StreamDecoder |
52 | | void decodeData(Buffer::Instance& data, bool end_stream) override; |
53 | | void decodeMetadata(Http::MetadataMapPtr&& metadata_map) override; |
54 | | |
55 | | // Http::ResponseDecoder |
56 | | void decode1xxHeaders(Http::ResponseHeaderMapPtr&& headers) override; |
57 | | void decodeHeaders(Http::ResponseHeaderMapPtr&& headers, bool end_stream) override; |
58 | | void decodeTrailers(Http::ResponseTrailerMapPtr&& trailers) override; |
59 | 0 | void dumpState(std::ostream& os, int indent_level) const override { |
60 | 0 | DUMP_STATE_UNIMPLEMENTED(DecoderShim); |
61 | 0 | } |
62 | | |
63 | | // Http::StreamCallbacks |
64 | | void onResetStream(Http::StreamResetReason reason, |
65 | | absl::string_view transport_failure_reason) override; |
66 | 0 | void onAboveWriteBufferHighWatermark() override {} |
67 | 0 | void onBelowWriteBufferLowWatermark() override {} |
68 | | |
69 | | private: |
70 | | Event::Dispatcher& dispatcher_; |
71 | | Http::ResponseHeaderMapPtr continue_headers_; |
72 | | Http::ResponseHeaderMapPtr headers_; |
73 | | Http::ResponseTrailerMapPtr trailers_; |
74 | | Http::MetadataMapPtr metadata_map_{new Http::MetadataMap()}; |
75 | | absl::node_hash_map<std::string, uint64_t> duplicated_metadata_key_count_; |
76 | | bool waiting_for_end_stream_{}; |
77 | | bool saw_end_stream_{}; |
78 | | std::string body_; |
79 | | uint64_t body_data_waiting_length_{}; |
80 | | bool waiting_for_reset_{}; |
81 | | bool waiting_for_continue_headers_{}; |
82 | | bool waiting_for_headers_{}; |
83 | | bool saw_reset_{}; |
84 | | Http::StreamResetReason reset_reason_{}; |
85 | | uint32_t metadata_maps_decoded_count_{}; |
86 | | }; |
87 | | |
88 | | using IntegrationStreamDecoderPtr = std::unique_ptr<IntegrationStreamDecoder>; |
89 | | |
90 | | } // namespace Envoy |