zwoop commented on code in PR #13160:
URL: https://github.com/apache/trafficserver/pull/13160#discussion_r3284503072
##########
plugins/experimental/maxmind_acl/mmdb.cc:
##########
@@ -139,6 +142,8 @@ Acl::init(char const *filename)
_anonymous_blocking = loadanonymous(maxmind["anonymous"]);
+ loadbypass(maxmind["bypass"]);
Review Comment:
Hmmm, your new `::loadbypass()` returns a bool, but as far as I can tell
this is the only call site, and you don't use the return value. Missing a
check, or should we just have this new function return void?
##########
plugins/experimental/maxmind_acl/mmdb.cc:
##########
@@ -503,6 +540,48 @@ Acl::loaddb(const YAML::Node &dbNode)
return true;
}
+bool
+Acl::check_bypass(TSHttpTxn txnp) const
+{
+ if (_bypass_header.empty()) {
+ return false;
+ }
+
+ TSMBuffer mbuf;
+ TSMLoc hdr_loc;
+ if (TS_SUCCESS != TSHttpTxnClientReqGet(txnp, &mbuf, &hdr_loc)) {
+ Dbg(dbg_ctl, "check_bypass: failed to get client request headers");
+ return false;
+ }
+
+ TSMLoc field_loc = TSMimeHdrFieldFind(mbuf, hdr_loc, _bypass_header.c_str(),
static_cast<int>(_bypass_header.size()));
+ if (TS_NULL_MLOC == field_loc) {
+ TSHandleMLocRelease(mbuf, TS_NULL_MLOC, hdr_loc);
+ return false;
+ }
+
+ bool bypassed = false;
+ if (_bypass_header_value.empty()) {
+ // presence-only check
+ Dbg(dbg_ctl, "check_bypass: bypass header '%s' present",
_bypass_header.c_str());
+ bypassed = true;
+ } else {
+ int val_len = 0;
+ const char *val = TSMimeHdrFieldValueStringGet(mbuf, hdr_loc,
field_loc, -1, &val_len);
+ if (val != nullptr && static_cast<int>(_bypass_header_value.size()) ==
val_len &&
Review Comment:
Nitpick, but this could use std::string's == operator overload
```
if (val != nullptr && _bypass_header_value == std::string_view{val,
static_cast<size_t>(val_len)}) {
```
more C++20 idiomatic. Optional change, your call.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]