/proc/self/cwd/source/extensions/filters/network/dubbo_proxy/message_impl.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "source/extensions/filters/network/dubbo_proxy/message_impl.h" |
2 | | |
3 | | #include "source/common/http/header_map_impl.h" |
4 | | |
5 | | namespace Envoy { |
6 | | namespace Extensions { |
7 | | namespace NetworkFilters { |
8 | | namespace DubboProxy { |
9 | | |
10 | | RpcInvocationImpl::Attachment::Attachment(MapPtr&& value, size_t offset) |
11 | 0 | : attachment_(std::move(value)), attachment_offset_(offset) { |
12 | 0 | headers_ = Http::RequestHeaderMapImpl::create(); |
13 | |
|
14 | 0 | ASSERT(attachment_ != nullptr); |
15 | 0 | ASSERT(attachment_->toMutableUntypedMap().has_value()); |
16 | | |
17 | 0 | for (const auto& pair : *attachment_) { |
18 | 0 | const auto key = pair.first->toString(); |
19 | 0 | const auto value = pair.second->toString(); |
20 | 0 | if (!key.has_value() || !value.has_value()) { |
21 | 0 | continue; |
22 | 0 | } |
23 | 0 | headers_->addCopy(Http::LowerCaseString(key.value().get()), value.value().get()); |
24 | 0 | } |
25 | 0 | } |
26 | | |
27 | 0 | void RpcInvocationImpl::Attachment::insert(const std::string& key, const std::string& value) { |
28 | 0 | attachment_updated_ = true; |
29 | |
|
30 | 0 | attachment_->emplace(std::make_unique<String>(key), std::make_unique<String>(value)); |
31 | |
|
32 | 0 | auto lowcase_key = Http::LowerCaseString(key); |
33 | 0 | headers_->remove(lowcase_key); |
34 | 0 | headers_->addCopy(lowcase_key, value); |
35 | 0 | } |
36 | | |
37 | 0 | void RpcInvocationImpl::Attachment::remove(const std::string& key) { |
38 | 0 | ASSERT(attachment_->toMutableUntypedMap().has_value()); |
39 | | |
40 | 0 | attachment_updated_ = true; |
41 | 0 | attachment_->toMutableUntypedMap().value().get().erase(key); |
42 | 0 | headers_->remove(Http::LowerCaseString(key)); |
43 | 0 | } |
44 | | |
45 | 0 | const std::string* RpcInvocationImpl::Attachment::lookup(const std::string& key) const { |
46 | 0 | ASSERT(attachment_->toMutableUntypedMap().has_value()); |
47 | | |
48 | 0 | auto& map = attachment_->toMutableUntypedMap().value().get(); |
49 | 0 | auto result = map.find(key); |
50 | 0 | if (result != map.end() && result->second->toString().has_value()) { |
51 | 0 | return &(result->second->toString().value().get()); |
52 | 0 | } |
53 | 0 | return nullptr; |
54 | 0 | } |
55 | | |
56 | 0 | void RpcInvocationImpl::assignParametersIfNeed() const { |
57 | 0 | ASSERT(parameters_lazy_callback_ != nullptr); |
58 | 0 | if (parameters_ == nullptr) { |
59 | 0 | parameters_ = parameters_lazy_callback_(); |
60 | 0 | } |
61 | 0 | } |
62 | | |
63 | 0 | void RpcInvocationImpl::assignAttachmentIfNeed() const { |
64 | 0 | ASSERT(attachment_lazy_callback_ != nullptr); |
65 | 0 | if (attachment_ != nullptr) { |
66 | 0 | return; |
67 | 0 | } |
68 | | |
69 | 0 | assignParametersIfNeed(); |
70 | 0 | attachment_ = attachment_lazy_callback_(); |
71 | |
|
72 | 0 | if (auto g = attachment_->lookup("group"); g != nullptr) { |
73 | 0 | const_cast<RpcInvocationImpl*>(this)->group_ = *g; |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | 0 | const absl::optional<std::string>& RpcInvocationImpl::serviceGroup() const { |
78 | 0 | assignAttachmentIfNeed(); |
79 | 0 | return group_; |
80 | 0 | } |
81 | | |
82 | 0 | const RpcInvocationImpl::Attachment& RpcInvocationImpl::attachment() const { |
83 | 0 | assignAttachmentIfNeed(); |
84 | 0 | return *attachment_; |
85 | 0 | } |
86 | | |
87 | 0 | RpcInvocationImpl::AttachmentPtr& RpcInvocationImpl::mutableAttachment() const { |
88 | 0 | assignAttachmentIfNeed(); |
89 | 0 | return attachment_; |
90 | 0 | } |
91 | | |
92 | 0 | const RpcInvocationImpl::Parameters& RpcInvocationImpl::parameters() const { |
93 | 0 | assignParametersIfNeed(); |
94 | 0 | return *parameters_; |
95 | 0 | } |
96 | | |
97 | 0 | RpcInvocationImpl::ParametersPtr& RpcInvocationImpl::mutableParameters() const { |
98 | 0 | assignParametersIfNeed(); |
99 | 0 | return parameters_; |
100 | 0 | } |
101 | | |
102 | | } // namespace DubboProxy |
103 | | } // namespace NetworkFilters |
104 | | } // namespace Extensions |
105 | | } // namespace Envoy |