This repository has been archived by the owner on Dec 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
/
autonomous_upstream.h
101 lines (84 loc) · 4.59 KB
/
autonomous_upstream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include "test/integration/fake_upstream.h"
namespace Envoy {
class AutonomousUpstream;
// A stream which automatically responds when the downstream request is
// completely read. By default the response is 200: OK with 10 bytes of
// payload. This behavior can be overridden with custom request headers defined below.
class AutonomousStream : public FakeStream {
public:
// The number of response bytes to send. Payload is randomized.
static const char RESPONSE_SIZE_BYTES[];
// The number of data blocks send.
static const char RESPONSE_DATA_BLOCKS[];
// If set to an integer, the AutonomousStream will expect the response body to
// be this large.
static const char EXPECT_REQUEST_SIZE_BYTES[];
// If set, the stream will reset when the request is complete, rather than
// sending a response.
static const char RESET_AFTER_REQUEST[];
// Prevents upstream from sending trailers.
static const char NO_TRAILERS[];
AutonomousStream(FakeHttpConnection& parent, Http::ResponseEncoder& encoder,
AutonomousUpstream& upstream, bool allow_incomplete_streams);
~AutonomousStream() override;
void setEndStream(bool set) EXCLUSIVE_LOCKS_REQUIRED(lock_) override;
private:
AutonomousUpstream& upstream_;
void sendResponse() EXCLUSIVE_LOCKS_REQUIRED(lock_);
const bool allow_incomplete_streams_{false};
};
// An upstream which creates AutonomousStreams for new incoming streams.
class AutonomousHttpConnection : public FakeHttpConnection {
public:
AutonomousHttpConnection(AutonomousUpstream& autonomous_upstream,
SharedConnectionWrapper& shared_connection, Type type,
AutonomousUpstream& upstream);
Http::RequestDecoder& newStream(Http::ResponseEncoder& response_encoder, bool) override;
private:
AutonomousUpstream& upstream_;
std::vector<FakeStreamPtr> streams_;
};
using AutonomousHttpConnectionPtr = std::unique_ptr<AutonomousHttpConnection>;
// An upstream which creates AutonomousHttpConnection for new incoming connections.
class AutonomousUpstream : public FakeUpstream {
public:
AutonomousUpstream(const Network::Address::InstanceConstSharedPtr& address,
FakeHttpConnection::Type type, Event::TestTimeSystem& time_system,
bool allow_incomplete_streams)
: FakeUpstream(address, type, time_system),
allow_incomplete_streams_(allow_incomplete_streams),
response_trailers_(std::make_unique<Http::TestResponseTrailerMapImpl>()),
response_headers_(std::make_unique<Http::TestResponseHeaderMapImpl>(
Http::TestResponseHeaderMapImpl({{":status", "200"}}))) {}
AutonomousUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory, uint32_t port,
FakeHttpConnection::Type type, Network::Address::IpVersion version,
Event::TestTimeSystem& time_system, bool allow_incomplete_streams)
: FakeUpstream(std::move(transport_socket_factory), port, type, version, time_system),
allow_incomplete_streams_(allow_incomplete_streams),
response_trailers_(std::make_unique<Http::TestResponseTrailerMapImpl>()),
response_headers_(std::make_unique<Http::TestResponseHeaderMapImpl>(
Http::TestResponseHeaderMapImpl({{":status", "200"}}))) {}
~AutonomousUpstream() override;
bool
createNetworkFilterChain(Network::Connection& connection,
const std::vector<Network::FilterFactoryCb>& filter_factories) override;
bool createListenerFilterChain(Network::ListenerFilterManager& listener) override;
void createUdpListenerFilterChain(Network::UdpListenerFilterManager& listener,
Network::UdpReadFilterCallbacks& callbacks) override;
void setLastRequestHeaders(const Http::HeaderMap& headers);
std::unique_ptr<Http::TestRequestHeaderMapImpl> lastRequestHeaders();
void setResponseTrailers(std::unique_ptr<Http::TestResponseTrailerMapImpl>&& response_trailers);
void setResponseHeaders(std::unique_ptr<Http::TestResponseHeaderMapImpl>&& response_headers);
Http::TestResponseTrailerMapImpl responseTrailers();
Http::TestResponseHeaderMapImpl responseHeaders();
const bool allow_incomplete_streams_{false};
private:
Thread::MutexBasicLockable headers_lock_;
std::unique_ptr<Http::TestRequestHeaderMapImpl> last_request_headers_;
std::unique_ptr<Http::TestResponseTrailerMapImpl> response_trailers_;
std::unique_ptr<Http::TestResponseHeaderMapImpl> response_headers_;
std::vector<AutonomousHttpConnectionPtr> http_connections_;
std::vector<SharedConnectionWrapperPtr> shared_connections_;
};
} // namespace Envoy