This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit d0a6a684dc307010185c446641f235ea9562a533 Author: Leif Hedstrom <[email protected]> AuthorDate: Mon May 20 13:33:16 2024 -0600 Some Cripts cleanup and fixes (#11369) (cherry picked from commit 54909439611df4647765ac85cf54aa2286dee29c) --- .../cripts/cripts-connections.en.rst | 4 ++-- doc/developer-guide/cripts/cripts-crypto.en.rst | 4 ++-- doc/developer-guide/cripts/cripts-matcher.en.rst | 4 ++-- doc/developer-guide/cripts/cripts-misc.en.rst | 4 ++-- doc/developer-guide/cripts/cripts-urls.en.rst | 6 +++--- doc/developer-guide/cripts/cripts-variables.en.rst | 11 +++++----- include/cripts/Error.hpp | 24 +++++++++++----------- include/cripts/Lulu.hpp | 24 ++++++++++++++++++---- include/cripts/Transaction.hpp | 6 +++++- src/cripts/Error.cc | 6 ++++-- tools/cripts/clang-tidy.conf | 1 - 11 files changed, 57 insertions(+), 37 deletions(-) diff --git a/doc/developer-guide/cripts/cripts-connections.en.rst b/doc/developer-guide/cripts/cripts-connections.en.rst index d2bbde2fe4..614eb220f4 100644 --- a/doc/developer-guide/cripts/cripts-connections.en.rst +++ b/doc/developer-guide/cripts/cripts-connections.en.rst @@ -97,14 +97,14 @@ Both connection objects provide a number of variables that can be accessed. Thes Variable Description ======================= ========================================================================= ``tcpinfo`` A number of TCPinfo related fields (see below). -``geo`` If available (compile time) acess to Geo-IP data (see below). +``geo`` If available (compile time) access to Geo-IP data (see below). ``congestion`` Configure the congestion algorithm used on the socket. ``pacing`` Configure socket pacing for the connection. ``dscp`` Manage the DSCP value for the connection socket. ``mark`` Manage the Mark value for the connection socket. ======================= ========================================================================= -For other advanced features, a cript has access to the socket file descriptor, via the ``fd()`` +For other advanced features, a Cript has access to the socket file descriptor, via the ``fd()`` method of the connection object. .. note:: diff --git a/doc/developer-guide/cripts/cripts-crypto.en.rst b/doc/developer-guide/cripts/cripts-crypto.en.rst index 77ace8f140..537d761f50 100644 --- a/doc/developer-guide/cripts/cripts-crypto.en.rst +++ b/doc/developer-guide/cripts/cripts-crypto.en.rst @@ -46,7 +46,7 @@ Object Description ``Crypto::HMAC::SHA256`` HMAC-SHA256 hashing. ================================= =============================================================== -These objects all provide a ``encod()`` and ``decode()`` method, to hash and unhash strings. +These objects all provide a ``encode()`` and ``decode()`` method, to hash and unhash strings. Examples: .. code-block:: cpp @@ -62,7 +62,7 @@ Encryption ========== Currently only one encryption object is provides, for AES256. This object provides -``encrypt()`` and ``decrypt()`` methods. A ``hex()`` method is also provided to retreive +``encrypt()`` and ``decrypt()`` methods. A ``hex()`` method is also provided to retrieve the encrypted data as a hex string. For encrypting data in chunks, a ``finalize()`` method is provided to retrieve the final encrypted data. diff --git a/doc/developer-guide/cripts/cripts-matcher.en.rst b/doc/developer-guide/cripts/cripts-matcher.en.rst index 4e9b7aa8df..fd099cb673 100644 --- a/doc/developer-guide/cripts/cripts-matcher.en.rst +++ b/doc/developer-guide/cripts/cripts-matcher.en.rst @@ -60,7 +60,7 @@ Here's an example using the regular expression matcher: For the IP-range and regular expression matcher, you can specify a single range or regular expression, it does not have to be declared as a list with the ``{}`` syntax. For both, the single or list arguments - are strings withing ``""``. + are strings within ``""``. .. _cripts-matchers-functions: @@ -92,7 +92,7 @@ Function Description ``matched()`` A boolean indicating if a regex was matched. ``count()`` Returns the number of regex capture groups that are matched. ``matchIX()`` Returns the index of the matched regex capture group. -[] Index Retrives the matched string for the given capture group index. +[] Index Retrieves the matched string for the given capture group index. ============================ ==================================================================== Lets show an example: diff --git a/doc/developer-guide/cripts/cripts-misc.en.rst b/doc/developer-guide/cripts/cripts-misc.en.rst index bffe53a82f..085731f6d8 100644 --- a/doc/developer-guide/cripts/cripts-misc.en.rst +++ b/doc/developer-guide/cripts/cripts-misc.en.rst @@ -115,7 +115,7 @@ Example usage to turn off a particular hook conditionally: } .. note:: - Disabling callbacks like this is an optimization, avoding for the hook to be called at all. + Disabling callbacks like this is an optimization, avoiding for the hook to be called at all. It can be particularly useful when the decision to run the hook is made early in the Cript. Time @@ -155,7 +155,7 @@ This opens up new possibilities for your existing plugins, as you gain the full power of Cript to decide when to run such plugins. Setting up existing remap plugins must be done in the ``do_create_instance()`` -hook. The instanatiated remap plugins must be added to the instance object for the +hook. The instantiated remap plugins must be added to the instance object for the Cript, using the ``addPlugin()`` method. Here's an example to run the rate limiting plugin based on the client request headers: diff --git a/doc/developer-guide/cripts/cripts-urls.en.rst b/doc/developer-guide/cripts/cripts-urls.en.rst index cdf11b4f0e..05f07595e0 100644 --- a/doc/developer-guide/cripts/cripts-urls.en.rst +++ b/doc/developer-guide/cripts/cripts-urls.en.rst @@ -26,7 +26,7 @@ Urls **** The URL objects are managed and own by the Cripts subsystem, and as such -must always be borrewed. The pattern for this is as follows: +must always be borrowed. The pattern for this is as follows: .. code-block:: cpp @@ -49,7 +49,7 @@ URL Object Description These URLs all have the same methods and properties, but they are used in different hooks and have different meanings. The ``Client::URL`` is the most commonly used URL, -which you will also modify in the tradtional remapping use case; for example changing +which you will also modify in the traditional remapping use case; for example changing the ``path`` or ``host`` before further processing. .. _cripts-urls-components: @@ -93,7 +93,7 @@ indexed in a list. To get the value of a specific query parameter, you can use t auto value = url.query["key"]; // This is the value of the key -You can retreive the size of the path or query using the ``size()`` method, and you can clear +You can retrieve the size of the path or query using the ``size()`` method, and you can clear the path or query using the ``erase()`` method. To summarize the ``path`` and ``query`` components have the following methods available to them: diff --git a/doc/developer-guide/cripts/cripts-variables.en.rst b/doc/developer-guide/cripts/cripts-variables.en.rst index f42d35e287..0b7b7f23ab 100644 --- a/doc/developer-guide/cripts/cripts-variables.en.rst +++ b/doc/developer-guide/cripts/cripts-variables.en.rst @@ -75,9 +75,9 @@ Method Description ``size()`` Return the length of the string. Also available as ``length()``. ``starts_with()`` Check if the string starts with a given string. ``ends_with()`` Check if the string ends with a given string. -``find()`` Find a string within the string. **TBD** -``rfind()`` Find a string within the string, starting from the end. **TBD** -``contains()`` Check if the string contains a given string. **TBD** +``find()`` Find a string within the string. +``rfind()`` Find a string within the string, starting from the end. +``contains()`` Check if the string contains a given string. ``substr()`` Get a substring of the string, arguments are ``start`` and ``end`` position. ``split()`` Split the string into a list of strings, using a delimiter. Returns a list. ``trim()`` Trim whitespace from the string. @@ -96,9 +96,8 @@ with strings. These are covered in more detail in the :ref:`cripts-matchers` sec regular comparisons such as ``==`` and ``!=`` are also available. .. note:: - - We'll continue to update features of Cripts as we start using it more in production. If you - have any suggestions or requests for strings (or any other data type), please let us know! + The ``find()`` and ``rfind()`` methods return the position of the string within the string, or + ``Cript::string_view::npos`` if the string is not found. .. _cripts-variables-configuration: diff --git a/include/cripts/Error.hpp b/include/cripts/Error.hpp index 64ec5e3329..3d1aa4380b 100644 --- a/include/cripts/Error.hpp +++ b/include/cripts/Error.hpp @@ -30,31 +30,31 @@ class Context; class Error { public: - class Message + class Reason { - using self_type = Message; + using self_type = Reason; public: - Message() = default; - Message(const Message &) = delete; - void operator=(const Message &) = delete; + Reason() = default; + Reason(const Reason &) = delete; + void operator=(const Reason &) = delete; static void _set(Cript::Context *context, const Cript::string_view msg); [[nodiscard]] Cript::string_view - message() const + reason() const { - return {_message.c_str(), _message.size()}; + return {_reason.c_str(), _reason.size()}; } private: void setter(const Cript::string_view msg) { - _message = msg; + _reason = msg; } - Cript::string _message; + Cript::string _reason; }; #undef Status @@ -112,7 +112,7 @@ public: void execute(Cript::Context *context); private: - Message _message; - Status _status; - bool _failed = false; + Reason _reason; + Status _status; + bool _failed = false; }; diff --git a/include/cripts/Lulu.hpp b/include/cripts/Lulu.hpp index d0d4d2fde0..af79a69a00 100644 --- a/include/cripts/Lulu.hpp +++ b/include/cripts/Lulu.hpp @@ -187,8 +187,6 @@ public: _value.remove_suffix(n); } - // ToDo: There are other members of std::string_view /swoc::TextView that we may want to incorporate here, - // to make the mixin class more complete. ChildT & ltrim(char c) { @@ -237,18 +235,36 @@ public: return _value.data_end(); } - [[nodiscard]] bool + [[nodiscard]] constexpr bool ends_with(Cript::string_view const suffix) const { return _value.ends_with(suffix); } - [[nodiscard]] bool + [[nodiscard]] constexpr bool starts_with(Cript::string_view const prefix) const { return _value.starts_with(prefix); } + [[nodiscard]] constexpr mixin_type::size_type + find(Cript::string_view const substr, mixin_type::size_type pos = 0) const + { + return _value.find(substr, pos); + } + + [[nodiscard]] constexpr mixin_type::size_type + rfind(Cript::string_view const substr, mixin_type::size_type pos = 0) const + { + return _value.rfind(substr, pos); + } + + [[nodiscard]] constexpr bool + contains(Cript::string_view const substr) const + { + return (_value.find(substr) != _value.npos); + } + protected: void _setSV(const mixin_type str) diff --git a/include/cripts/Transaction.hpp b/include/cripts/Transaction.hpp index 5b0be94a49..18dda388b8 100644 --- a/include/cripts/Transaction.hpp +++ b/include/cripts/Transaction.hpp @@ -65,7 +65,11 @@ public: { bool client_abort = false; - return (TSHttpTxnAborted(txnp, &client_abort) == TS_SUCCESS); + if (TSHttpTxnAborted(txnp, &client_abort) == TS_SUCCESS) { + return client_abort; + } + + return false; } [[nodiscard]] int diff --git a/src/cripts/Error.cc b/src/cripts/Error.cc index eced78357e..4dd2d700d8 100644 --- a/src/cripts/Error.cc +++ b/src/cripts/Error.cc @@ -24,15 +24,17 @@ Error::execute(Cript::Context *context) { if (failed()) { TSHttpTxnStatusSet(context->state.txnp, _status.status()); + // ToDo: So we can't set the reason phrase here, because ATS doesn't have that + // as a transaction API, only on the response header... } } // These are static, to be used with the set() wrapper define void -Error::Message::_set(Cript::Context *context, const Cript::string_view msg) +Error::Reason::_set(Cript::Context *context, const Cript::string_view msg) { context->state.error.fail(); - context->state.error._message.setter(msg); + context->state.error._reason.setter(msg); } void diff --git a/tools/cripts/clang-tidy.conf b/tools/cripts/clang-tidy.conf index 2e6b990206..18d4783c7d 100644 --- a/tools/cripts/clang-tidy.conf +++ b/tools/cripts/clang-tidy.conf @@ -2,7 +2,6 @@ Checks: "performance-*,modernize-*,google-*,clang-diagnostic-*,clang-analyzer-*,-google-readability-casting,-google-explicit-constructor,-modernize-use-trailing-return-type,-google-global-names-in-headers,-modernize-avoid-c-arrays" WarningsAsErrors: "" HeaderFilterRegex: "(Cript|src)/.*" -AnalyzeTemporaryDtors: false FormatStyle: none CheckOptions: - key: llvm-else-after-return.WarnOnConditionVariables
