-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add header matched routing #110
Changes from 1 commit
9b6d1d3
63e84ff
4c3530a
f0bdcf0
e60f559
ec89aaa
b11c97c
0312d14
9b31a8d
414cda4
646133f
d0ecefd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,21 @@ RouteEntryImplBase::RouteEntryImplBase(const VirtualHost& vhost, const Json::Obj | |
} | ||
|
||
if (route.hasObject("headers")) { | ||
config_headers_ = route.getObjectArray("headers"); | ||
std::vector<Json::Object> config_headers = route.getObjectArray("headers"); | ||
for (const Json::Object& header_map : config_headers) { | ||
HeaderData header_data; | ||
|
||
if (!header_map.hasObject("header_name")) { | ||
throw EnvoyException("headers in the route config must have a header name"); | ||
} else { | ||
header_data.header_name_ = header_map.getString("header_name"); | ||
} | ||
|
||
// allow header value to be empty, allows matching to be only based on header presence. | ||
header_data.header_value_ = header_map.getString("header_value"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs default value of "" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. |
||
|
||
config_headers_.push_back(header_data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. push_back struct directly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can emplace_back(header_map.getString("header_name"), header_map.getString("header_value", "")) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like emplace_back would not allow me to do uniform initialization Important edit: @RomanDzhabarov you were right all along! |
||
} | ||
} | ||
} | ||
|
||
|
@@ -84,8 +98,8 @@ bool RouteEntryImplBase::matches(const Http::HeaderMap& headers, uint64_t random | |
} | ||
|
||
if (!config_headers_.empty()) { | ||
for (const Json::Object& header_map : config_headers_) { | ||
matches &= headers.get(Http::LowerCaseString(header_map.getString("header_name"))) == header_map.getString("header_value"); | ||
for (const HeaderData header_data : config_headers_) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const HeaderData& There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
matches &= headers.get(Http::LowerCaseString(header_data.header_name_)) == header_data.header_value_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. store as lower case string in the struct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. storing as Http::LowerCaseString |
||
if (!matches) { | ||
break; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,11 @@ class RouteEntryImplBase : public RouteEntry, public Matchable, public RedirectE | |
uint64_t default_; | ||
}; | ||
|
||
struct HeaderData { | ||
std::string header_name_; | ||
std::string header_value_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
}; | ||
|
||
static Optional<RuntimeData> loadRuntimeData(const Json::Object& route); | ||
|
||
// Default timeout is 15s if nothing is specified in the route config. | ||
|
@@ -211,7 +216,7 @@ class RouteEntryImplBase : public RouteEntry, public Matchable, public RedirectE | |
const RateLimitPolicyImpl rate_limit_policy_; | ||
const ShadowPolicyImpl shadow_policy_; | ||
const Upstream::ResourcePriority priority_; | ||
std::vector<Json::Object> config_headers_; | ||
std::vector<HeaderData> config_headers_; | ||
}; | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't bother with this check here. Just let JsonException be thrown if value does not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will let JsonException be thrown.