-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into ci_gcs_remote_cache
- Loading branch information
Showing
22 changed files
with
1,281 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "envoy/common/exception.h" | ||
#include "envoy/common/pure.h" | ||
|
||
#include "common/common/fmt.h" | ||
|
||
#include "absl/strings/string_view.h" | ||
|
||
namespace Envoy { | ||
namespace RequestInfo { | ||
|
||
class DynamicMetadata { | ||
public: | ||
class Object { | ||
public: | ||
virtual ~Object(){}; | ||
}; | ||
|
||
virtual ~DynamicMetadata(){}; | ||
|
||
/** | ||
* @param data_name the name of the data being set. | ||
* @param data an owning pointer to the data to be stored. | ||
* Note that it is an error to call setData() twice with the same data_name; this is to | ||
* enforce a single authoritative source for each piece of data stored in DynamicMetadata. | ||
*/ | ||
virtual void setData(absl::string_view data_name, std::unique_ptr<Object>&& data) PURE; | ||
|
||
/** | ||
* @param data_name the name of the data being set. | ||
* @return a reference to the stored data. | ||
* Note that it is an error to access data that has not previously been set. | ||
* This function will fail if the data stored under |data_name| cannot be | ||
* dynamically cast to the type specified. | ||
*/ | ||
template <typename T> const T& getData(absl::string_view data_name) const { | ||
const T* result = dynamic_cast<const T*>(getDataGeneric(data_name)); | ||
if (!result) { | ||
throw EnvoyException( | ||
fmt::format("Data stored under {} cannot be coerced to specified type", data_name)); | ||
} | ||
return *result; | ||
} | ||
|
||
/** | ||
* @param data_name the name of the data being probed. | ||
* @return Whether data of the type and name specified exists in the | ||
* data store. | ||
*/ | ||
template <typename T> bool hasData(absl::string_view data_name) const { | ||
return (hasDataWithName(data_name) && | ||
(dynamic_cast<const T*>(getDataGeneric(data_name)) != nullptr)); | ||
} | ||
|
||
/** | ||
* @param data_name the name of the data being probed. | ||
* @return Whether data of any type and the name specified exists in the | ||
* data store. | ||
*/ | ||
virtual bool hasDataWithName(absl::string_view data_name) const PURE; | ||
|
||
protected: | ||
virtual const Object* getDataGeneric(absl::string_view data_name) const PURE; | ||
}; | ||
|
||
} // namespace RequestInfo | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "common/request_info/dynamic_metadata_impl.h" | ||
|
||
#include "envoy/common/exception.h" | ||
|
||
namespace Envoy { | ||
namespace RequestInfo { | ||
|
||
void DynamicMetadataImpl::setData(absl::string_view data_name, std::unique_ptr<Object>&& data) { | ||
if (data_storage_.find(data_name) != data_storage_.end()) { | ||
throw EnvoyException("DynamicMetadata::setData<T> called twice with same name."); | ||
} | ||
// absl::string_view will not convert to std::string without an explicit case; see | ||
// https://github.com/abseil/abseil-cpp/blob/master/absl/strings/string_view.h#L328 | ||
data_storage_[static_cast<std::string>(data_name)] = std::move(data); | ||
} | ||
|
||
bool DynamicMetadataImpl::hasDataWithName(absl::string_view data_name) const { | ||
return data_storage_.count(data_name) > 0; | ||
} | ||
|
||
const DynamicMetadata::Object* | ||
DynamicMetadataImpl::getDataGeneric(absl::string_view data_name) const { | ||
const auto& it = data_storage_.find(data_name); | ||
|
||
if (it == data_storage_.end()) { | ||
throw EnvoyException("DynamicMetadata::getData<T> called for unknown data name."); | ||
} | ||
return it->second.get(); | ||
} | ||
|
||
} // namespace RequestInfo | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
#include "envoy/request_info/dynamic_metadata.h" | ||
|
||
#include "absl/strings/string_view.h" | ||
|
||
namespace Envoy { | ||
namespace RequestInfo { | ||
|
||
class DynamicMetadataImpl : public DynamicMetadata { | ||
public: | ||
// DynamicMetadata | ||
void setData(absl::string_view data_name, std::unique_ptr<Object>&& data) override; | ||
bool hasDataWithName(absl::string_view) const override; | ||
const Object* getDataGeneric(absl::string_view data_name) const override; | ||
|
||
private: | ||
// The explicit non-type-specific comparator is necessary to allow use of find() method | ||
// with absl::string_view. See | ||
// https://stackoverflow.com/questions/20317413/what-are-transparent-comparators. | ||
std::map<std::string, std::unique_ptr<Object>, std::less<>> data_storage_; | ||
}; | ||
|
||
} // namespace RequestInfo | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
actions { | ||
new_stream { | ||
request_headers { | ||
headers { | ||
key: ":method" | ||
value: "GET" | ||
} | ||
headers { | ||
key: ":path" | ||
value: "/" | ||
} | ||
headers { | ||
key: ":scheme" | ||
value: "http" | ||
} | ||
headers { | ||
key: ":authority" | ||
value: "foo.com" | ||
} | ||
headers { | ||
key: "expect" | ||
value: "100-continue" | ||
} | ||
} | ||
} | ||
} | ||
actions { quiesce_drain {} } | ||
actions { | ||
stream_action { | ||
stream_id: 0 | ||
response { | ||
continue_100_headers { | ||
headers { | ||
key: ":status" | ||
value: "100" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
actions { quiesce_drain {} } | ||
actions { | ||
stream_action { | ||
stream_id: 0 | ||
response { | ||
headers { | ||
headers { | ||
key: ":status" | ||
value: "404" | ||
} | ||
} | ||
end_stream: true | ||
} | ||
} | ||
} | ||
actions { quiesce_drain {} } |
Empty file.
Oops, something went wrong.