You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "zwoop (via GitHub)" <gi...@apache.org> on 2023/08/16 16:00:30 UTC
[GitHub] [trafficserver] zwoop opened a new pull request, #10191: Import of the Cripts scripting / plugin wrapper library and includes
zwoop opened a new pull request, #10191:
URL: https://github.com/apache/trafficserver/pull/10191
Cripts tries to solves 90% of your problems, making it simple to do the most common tasks. It achieves this by managing the data needed for such tasks, using a per transaction context.
It doesn't support complex operations such as transforms, or server intercepts. It also only supports building with CMake in this version.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1320066136
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
Review Comment:
Nice.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1313229895
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
Review Comment:
This line could use a comment. I assume this is a chain of function calls configuring various aspects of the connection/transaction.
Is the dscp here referring to IP QoS classification?
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
+ resp["X-AMC"] = msg; // New header
+ resp["Cache-Control"] = "Private"; // Deletes old CC values, and sets a new one
+ resp["X-UUID"] = UUID::Unique::get();
+ resp["X-tcpinfo"] = conn.tcpinfo.log();
+ resp["X-Cache-Status"] = resp.cache;
+ resp["X-Integer"] = 666;
+ resp["X-Data"] = AsString(txn_data[2]);
+
+ resp["X-ASN"] = conn.geo.ASN();
+ resp["X-ASN-Name"] = conn.geo.ASNName();
+ resp["X-Country"] = conn.geo.Country();
+ resp["X-ISO-Country"] = conn.geo.CountryCode();
+
+ // Setup some connection parameters
+ conn.congestion = "bbr";
+ conn.dscp = 8;
+ conn.pacing = 100000;
+
+ // Some file operations (note that the paths aren't required here, can just be strings, but it's a good practice)
+ static const File::Path p1("/tmp/foo");
+ static const File::Path p2("/tmp/secret.txt");
+
+ if (File::Status(p1).type() == File::Type::regular) {
+ resp["X-Foo-Exists"] = "yes";
+ } else {
+ resp["X-Foo-Exists"] = "no";
+ }
+
+ string secret = File::Line::Reader(p2);
+ CDebug("Read secret = {}", secret);
+
+ if (resp.status == 200) {
+ resp.status = 222;
+ }
+
+ borrow url2 = Cache::URL::get();
+
+ CDebug("Cache URL: {}", url2.url());
+ CDebug("Cache Host: {}", url2.host);
+ CDebug("Txn count: {}", conn.count());
+}
+
+do_remap()
+{
+ auto now = Time::Local::now();
+ borrow req = Client::Request::get();
+ borrow conn = Client::Connection::get();
+ auto ip = conn.ip();
+
+ if (CRIPT_ALLOW.contains(ip)) {
+ CDebug("Client IP allowed: {}", ip.string(24, 64));
+ }
+
+ CDebug("Epoch time is {} (or via .epoch(), {}", now, now.epoch());
+ CDebug("Year is {}", now.year());
+ CDebug("Month is {}", now.month());
+ CDebug("Day is {}", now.day());
+ CDebug("Hour is {}", now.hour());
+ CDebug("Day number is {}", now.yearday());
+
+ CDebug("from_url = {}", instance.from_url.c_str());
+ CDebug("to_url = {}", instance.to_url.c_str());
+
+ // Turn off the cache for testing
+ // proxy.config.http.cache.http.set(1);
+ // control.cache.nostore.set(true);
+
+ CDebug("Int config cache.http = {}", proxy.config.http.cache.http.get());
+ CDebug("Float config cache.heuristic_lm_factor = {}", proxy.config.http.cache.heuristic_lm_factor.get());
+ CDebug("X-Miles = {}", req["X-Miles"]);
+ CDebug("random(1000) = {}", Cript::random(1000));
+
+ borrow url = Pristine::URL::get();
+ auto old_port = url.port;
+
+ CDebug("Method is {}", req.method);
+ CDebug("Scheme is {}", url.scheme);
+ CDebug("Host is {}", url.host);
+ CDebug("Port is {}", url.port);
+ CDebug("Path is {}", url.path);
+ CDebug("Path[1] is {}", url.path[1]);
+ CDebug("Query is {}", url.query);
+
+ if (url.query["foo"] > 100) {
+ CDebug("Query[foo] is > 100");
+ }
+
+ if (url.path == "some/url" || url.path[0] == "other") {
+ CDebug("The path comparison triggered");
+ }
+
+ url.host = "foobar.com";
+ url.port = "81";
+ url.port = old_port;
+
+ // TXN data slots
+ txn_data[0] = true;
+ txn_data[1] = 17;
+ txn_data[2] = "DBJ";
+
+ // Regular expressions
+ static Matcher::PCRE pcre("^/([^/]+)/(.*)$");
+
+ auto res = pcre.match("/foo/bench/bar"); // Can also call contains(), same thing
+
+ if (res) {
+ CDebug("Ovector count is {}", res.count());
+ CDebug("First capture is {}", res[1]);
+ CDebug("Second capture is {}", res[2]);
+ } else {
+ CDebug("Regular expression did not match, that is not expected!");
+ }
+
+ // ATS versions
+ CDebug("ATS version = {}", version);
+ CDebug("ATS Major Version = {}", version.major);
+
+ // Some Crypto::Base64 tests
+ static auto base64_test = "VGltZSB3aWxsIG5vdCBzbG93IGRvd24gd2hlbiBzb21ldGhpbmcgdW5wbGVhc2FudCBsaWVzIGFoZWFkLg==";
+ auto hp = Crypto::Base64::decode(base64_test);
+ auto hp2 = Crypto::Base64::encode(hp);
+
+ CDebug("HP quote: {}", hp);
+ if (base64_test != hp2) {
+ CDebug("Base64 failed: {}", hp2);
+ } else {
+ CDebug("Base64 encode reproduced the decoded HP string");
+ }
+
+ // Some Crypto::Escape (URL escaping) tests
+ static auto escape_test = "Hello_World_!@%23$%25%5E&*()_%2B%3C%3E?%2C.%2F";
+ auto uri = Crypto::Escape::decode(escape_test);
+ auto uri2 = Crypto::Escape::encode(uri);
+
+ CDebug("Unescaped URI: {}", uri);
+ if (escape_test != uri2) {
+ CDebug("URL Escape failed: {}", uri2);
+ } else {
+ CDebug("Url Escape encode reproduced the decoded HP string");
+ }
+
+ // Testing Crypto SHA and encryption
+ auto hex = format("{}", Crypto::SHA256::encode("Hello World"));
+
+ CDebug("SHA256 = {}", hex);
+
+ // Testing iterators
+ for (auto hdr : req) {
+ CDebug("Header: {} = {}", hdr, req[hdr]);
+ if (hdr.starts_with("AWS-")) {
+ req[hdr].clear();
+ }
+ }
+
+ // Testing some simple metrics
+ static auto m1 = Metrics::Sum("cript.example1`.m1");
+ static auto m2 = Metrics::Counter("cript.example1`.m2");
+
+ m1.increment(100);
+ m2.increment();
+
+ instance.metrics[0]->increment();
+ instance.metrics[8]->increment();
+}
+
+#include <cripts/Epilogue.hpp>
Review Comment:
Is this needed at the end of every cripts script? If so, let's add a comment here saying as such similar to the comment you have for for the Preamble.h include.
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
Review Comment:
Am I understanding correctly that every Cript plugin gets its own `instance` for free? That's kind of cool. That should make txn/session/whatever plugin handling safer.
How does a Cript plugin store its arbitrary data in instance?
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
+ resp["X-AMC"] = msg; // New header
+ resp["Cache-Control"] = "Private"; // Deletes old CC values, and sets a new one
+ resp["X-UUID"] = UUID::Unique::get();
+ resp["X-tcpinfo"] = conn.tcpinfo.log();
+ resp["X-Cache-Status"] = resp.cache;
+ resp["X-Integer"] = 666;
+ resp["X-Data"] = AsString(txn_data[2]);
+
+ resp["X-ASN"] = conn.geo.ASN();
+ resp["X-ASN-Name"] = conn.geo.ASNName();
+ resp["X-Country"] = conn.geo.Country();
+ resp["X-ISO-Country"] = conn.geo.CountryCode();
+
+ // Setup some connection parameters
+ conn.congestion = "bbr";
+ conn.dscp = 8;
+ conn.pacing = 100000;
+
+ // Some file operations (note that the paths aren't required here, can just be strings, but it's a good practice)
+ static const File::Path p1("/tmp/foo");
+ static const File::Path p2("/tmp/secret.txt");
+
+ if (File::Status(p1).type() == File::Type::regular) {
+ resp["X-Foo-Exists"] = "yes";
+ } else {
+ resp["X-Foo-Exists"] = "no";
+ }
+
+ string secret = File::Line::Reader(p2);
+ CDebug("Read secret = {}", secret);
+
+ if (resp.status == 200) {
+ resp.status = 222;
+ }
+
+ borrow url2 = Cache::URL::get();
+
+ CDebug("Cache URL: {}", url2.url());
+ CDebug("Cache Host: {}", url2.host);
+ CDebug("Txn count: {}", conn.count());
+}
+
+do_remap()
+{
+ auto now = Time::Local::now();
+ borrow req = Client::Request::get();
+ borrow conn = Client::Connection::get();
+ auto ip = conn.ip();
+
+ if (CRIPT_ALLOW.contains(ip)) {
+ CDebug("Client IP allowed: {}", ip.string(24, 64));
+ }
+
+ CDebug("Epoch time is {} (or via .epoch(), {}", now, now.epoch());
+ CDebug("Year is {}", now.year());
+ CDebug("Month is {}", now.month());
+ CDebug("Day is {}", now.day());
+ CDebug("Hour is {}", now.hour());
+ CDebug("Day number is {}", now.yearday());
+
+ CDebug("from_url = {}", instance.from_url.c_str());
+ CDebug("to_url = {}", instance.to_url.c_str());
+
+ // Turn off the cache for testing
+ // proxy.config.http.cache.http.set(1);
+ // control.cache.nostore.set(true);
Review Comment:
Setting configuration like this looks pretty convenient. I assume we'll only expose configurable parameters for overridable configurations?
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
Review Comment:
I don't think we can assume that an empty value implies field deletion. It's valid for an HTTP field to have an empty value. `Accept-Encoding`, for instance, can have an empty value and it has a particular meaning:
https://www.rfc-editor.org/rfc/rfc2616#section-14.3
> If the Accept-Encoding field-value is empty, then only the "identity" encoding is acceptable.
I suspect we need to have a `.delete()` function or something like it.
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
Review Comment:
* As I review this, this example1.cc is the most important file in this patch. And I suspect this will be the case for others using this too who will go to this and hopefully other example Cript files. You have some great comments here, but **let's multiply them by 10.** At the start here, lets include an introductory comment explaining some of the philosophies of Cripts (I think you can copy and paste your description from this PR), and an explanation of what this example Cripts script does. I just skimmed through the script and it's not obvious to me yet what this does. Maybe it doesn't do anything specific other than highlight some features, which is fine for one example file.
* A question on terminology: are we calling these files "cripts", "scripts", "plugins", or something else? Maybe a "cript plugin"?
* Do you plan to add to the `docs/` for Cripts in a separate PR?
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
+ resp["X-AMC"] = msg; // New header
+ resp["Cache-Control"] = "Private"; // Deletes old CC values, and sets a new one
+ resp["X-UUID"] = UUID::Unique::get();
+ resp["X-tcpinfo"] = conn.tcpinfo.log();
+ resp["X-Cache-Status"] = resp.cache;
+ resp["X-Integer"] = 666;
+ resp["X-Data"] = AsString(txn_data[2]);
+
+ resp["X-ASN"] = conn.geo.ASN();
+ resp["X-ASN-Name"] = conn.geo.ASNName();
+ resp["X-Country"] = conn.geo.Country();
+ resp["X-ISO-Country"] = conn.geo.CountryCode();
+
+ // Setup some connection parameters
+ conn.congestion = "bbr";
+ conn.dscp = 8;
+ conn.pacing = 100000;
+
+ // Some file operations (note that the paths aren't required here, can just be strings, but it's a good practice)
Review Comment:
I assume then that `p3("bar");` would refer to a file named `bar` in the pwd of the traffic server process?
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] ezelkow1 commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "ezelkow1 (via GitHub)" <gi...@apache.org>.
ezelkow1 commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1686748145
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1320075256
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
Review Comment:
Is this an autogenerated table of contents? If so, to keep it updated, lets add `<!---` describing how to generate it.
I do this in the yahoo/proxy-verifier README.md:
https://github.com/yahoo/proxy-verifier/blob/e0f644464018198e5e0c248dbe40918eacb55ebb/README.md?plain=1#L1-L12
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
Review Comment:
Suggest: `, for making` -> `that make`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
Review Comment:
Lets tell markdown this is c++ code:
```md
```cpp
```
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] ezelkow1 commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "ezelkow1 (via GitHub)" <gi...@apache.org>.
ezelkow1 commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1686772165
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1326534424
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
+latter will not exist on a cache miss, and should therefore only be used
+in callbacks involving origin transactions (*cache misses*).
+
+Accessing the client connections is easily done with
+
+```
+borrow conn = Client::Connection::get();
+```
+
+TODO: More stuff here, explaining the details
+
+## 3.6. Overridable configurations
+In ATS, some (not all) configurations can be overriden per transaction, or
+remap rule. Cripts supports all such configurations, in a way that retains
+the naming from `records.config`! Examples:
+
+```
+proxy.config.http.cache.http.set(0);
+
+if (proxy.config.http.cache.generation.get() > 0) {
+ // Do something
+}
+```
Review Comment:
There is one, right above it :)
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] ezelkow1 commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "ezelkow1 (via GitHub)" <gi...@apache.org>.
ezelkow1 commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1686750711
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] traeak commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "traeak (via GitHub)" <gi...@apache.org>.
traeak commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1693457321
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316388634
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
Review Comment:
You already have it :).
```
resp["Good-Brian"].clear();
```
or
```
resp.erase("Good-Brian");
```
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1323602022
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
+latter will not exist on a cache miss, and should therefore only be used
+in callbacks involving origin transactions (*cache misses*).
+
+Accessing the client connections is easily done with
Review Comment:
The README goes away once we land this and document, I'm not going to edit it.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] JosiahWI commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "JosiahWI (via GitHub)" <gi...@apache.org>.
JosiahWI commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1296311795
##########
example/cripts/CMakeLists.txt:
##########
@@ -0,0 +1,51 @@
+# ##############################################################################
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with this work for
+# additional information regarding copyright ownership. The ASF licenses this
+# file to you under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+#
+# ##############################################################################
+
+# Todo: It'd be useful to build all Cripts that are put into this directory,
+# using GLOB etc. like this:
+# file(GLOB CRIPTS_EXAMPLES ${PROJECT_SOURCE_DIR}/example/cripts/*.cc)
+#
+# foreach(EXA ${CRIPTS_EXAMPLES})
+# get_filename_component(EXA ${EXA} NAME_WLE)
+# ....
+# endforeach()
+
+add_atsplugin(cripts_example1 example1.cc)
+
+target_include_directories(cripts_example1 PRIVATE "${PROJECT_SOURCE_DIR}/include")
+target_link_libraries(cripts_example1 PRIVATE ts::cripts)
+
+# This is a hack, but useful to run clang-tidy across all of Cripts
+# Todo: why is this not working??
+#find_package(fmt 8.1 REQUIRED)
+#$<TARGET_PROPERTY:fmt::fmt,INCLUDE_DIRECTORIES>
+
Review Comment:
What is it supposed to do? First thing that stands out is that the generator expression probably needs to go inside some other command?
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1686743141
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316380054
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
Review Comment:
1. There's some of this in the README that I added.
2. Cripts
3. Yes.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316379371
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
+ resp["X-AMC"] = msg; // New header
+ resp["Cache-Control"] = "Private"; // Deletes old CC values, and sets a new one
+ resp["X-UUID"] = UUID::Unique::get();
+ resp["X-tcpinfo"] = conn.tcpinfo.log();
+ resp["X-Cache-Status"] = resp.cache;
+ resp["X-Integer"] = 666;
+ resp["X-Data"] = AsString(txn_data[2]);
+
+ resp["X-ASN"] = conn.geo.ASN();
+ resp["X-ASN-Name"] = conn.geo.ASNName();
+ resp["X-Country"] = conn.geo.Country();
+ resp["X-ISO-Country"] = conn.geo.CountryCode();
+
+ // Setup some connection parameters
+ conn.congestion = "bbr";
+ conn.dscp = 8;
+ conn.pacing = 100000;
+
+ // Some file operations (note that the paths aren't required here, can just be strings, but it's a good practice)
+ static const File::Path p1("/tmp/foo");
+ static const File::Path p2("/tmp/secret.txt");
+
+ if (File::Status(p1).type() == File::Type::regular) {
+ resp["X-Foo-Exists"] = "yes";
+ } else {
+ resp["X-Foo-Exists"] = "no";
+ }
+
+ string secret = File::Line::Reader(p2);
+ CDebug("Read secret = {}", secret);
+
+ if (resp.status == 200) {
+ resp.status = 222;
+ }
+
+ borrow url2 = Cache::URL::get();
+
+ CDebug("Cache URL: {}", url2.url());
+ CDebug("Cache Host: {}", url2.host);
+ CDebug("Txn count: {}", conn.count());
+}
+
+do_remap()
+{
+ auto now = Time::Local::now();
+ borrow req = Client::Request::get();
+ borrow conn = Client::Connection::get();
+ auto ip = conn.ip();
+
+ if (CRIPT_ALLOW.contains(ip)) {
+ CDebug("Client IP allowed: {}", ip.string(24, 64));
+ }
+
+ CDebug("Epoch time is {} (or via .epoch(), {}", now, now.epoch());
+ CDebug("Year is {}", now.year());
+ CDebug("Month is {}", now.month());
+ CDebug("Day is {}", now.day());
+ CDebug("Hour is {}", now.hour());
+ CDebug("Day number is {}", now.yearday());
+
+ CDebug("from_url = {}", instance.from_url.c_str());
+ CDebug("to_url = {}", instance.to_url.c_str());
+
+ // Turn off the cache for testing
+ // proxy.config.http.cache.http.set(1);
+ // control.cache.nostore.set(true);
+
+ CDebug("Int config cache.http = {}", proxy.config.http.cache.http.get());
+ CDebug("Float config cache.heuristic_lm_factor = {}", proxy.config.http.cache.heuristic_lm_factor.get());
+ CDebug("X-Miles = {}", req["X-Miles"]);
+ CDebug("random(1000) = {}", Cript::random(1000));
+
+ borrow url = Pristine::URL::get();
+ auto old_port = url.port;
+
+ CDebug("Method is {}", req.method);
+ CDebug("Scheme is {}", url.scheme);
+ CDebug("Host is {}", url.host);
+ CDebug("Port is {}", url.port);
+ CDebug("Path is {}", url.path);
+ CDebug("Path[1] is {}", url.path[1]);
+ CDebug("Query is {}", url.query);
+
+ if (url.query["foo"] > 100) {
+ CDebug("Query[foo] is > 100");
+ }
+
+ if (url.path == "some/url" || url.path[0] == "other") {
+ CDebug("The path comparison triggered");
+ }
+
+ url.host = "foobar.com";
+ url.port = "81";
+ url.port = old_port;
+
+ // TXN data slots
+ txn_data[0] = true;
+ txn_data[1] = 17;
+ txn_data[2] = "DBJ";
+
+ // Regular expressions
+ static Matcher::PCRE pcre("^/([^/]+)/(.*)$");
+
+ auto res = pcre.match("/foo/bench/bar"); // Can also call contains(), same thing
+
+ if (res) {
+ CDebug("Ovector count is {}", res.count());
+ CDebug("First capture is {}", res[1]);
+ CDebug("Second capture is {}", res[2]);
+ } else {
+ CDebug("Regular expression did not match, that is not expected!");
+ }
+
+ // ATS versions
+ CDebug("ATS version = {}", version);
+ CDebug("ATS Major Version = {}", version.major);
+
+ // Some Crypto::Base64 tests
+ static auto base64_test = "VGltZSB3aWxsIG5vdCBzbG93IGRvd24gd2hlbiBzb21ldGhpbmcgdW5wbGVhc2FudCBsaWVzIGFoZWFkLg==";
+ auto hp = Crypto::Base64::decode(base64_test);
+ auto hp2 = Crypto::Base64::encode(hp);
+
+ CDebug("HP quote: {}", hp);
+ if (base64_test != hp2) {
+ CDebug("Base64 failed: {}", hp2);
+ } else {
+ CDebug("Base64 encode reproduced the decoded HP string");
+ }
+
+ // Some Crypto::Escape (URL escaping) tests
+ static auto escape_test = "Hello_World_!@%23$%25%5E&*()_%2B%3C%3E?%2C.%2F";
+ auto uri = Crypto::Escape::decode(escape_test);
+ auto uri2 = Crypto::Escape::encode(uri);
+
+ CDebug("Unescaped URI: {}", uri);
+ if (escape_test != uri2) {
+ CDebug("URL Escape failed: {}", uri2);
+ } else {
+ CDebug("Url Escape encode reproduced the decoded HP string");
+ }
+
+ // Testing Crypto SHA and encryption
+ auto hex = format("{}", Crypto::SHA256::encode("Hello World"));
+
+ CDebug("SHA256 = {}", hex);
+
+ // Testing iterators
+ for (auto hdr : req) {
+ CDebug("Header: {} = {}", hdr, req[hdr]);
+ if (hdr.starts_with("AWS-")) {
+ req[hdr].clear();
+ }
+ }
+
+ // Testing some simple metrics
+ static auto m1 = Metrics::Sum("cript.example1`.m1");
+ static auto m2 = Metrics::Counter("cript.example1`.m2");
+
+ m1.increment(100);
+ m2.increment();
+
+ instance.metrics[0]->increment();
+ instance.metrics[8]->increment();
+}
+
+#include <cripts/Epilogue.hpp>
Review Comment:
Yes, required. I think it's documented in the README, but docs will be worked on if we agree to land this.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316390921
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
+ resp["X-AMC"] = msg; // New header
+ resp["Cache-Control"] = "Private"; // Deletes old CC values, and sets a new one
+ resp["X-UUID"] = UUID::Unique::get();
+ resp["X-tcpinfo"] = conn.tcpinfo.log();
+ resp["X-Cache-Status"] = resp.cache;
+ resp["X-Integer"] = 666;
+ resp["X-Data"] = AsString(txn_data[2]);
+
+ resp["X-ASN"] = conn.geo.ASN();
+ resp["X-ASN-Name"] = conn.geo.ASNName();
+ resp["X-Country"] = conn.geo.Country();
+ resp["X-ISO-Country"] = conn.geo.CountryCode();
+
+ // Setup some connection parameters
+ conn.congestion = "bbr";
+ conn.dscp = 8;
+ conn.pacing = 100000;
+
+ // Some file operations (note that the paths aren't required here, can just be strings, but it's a good practice)
Review Comment:
Yes, I think so :). It uses std::filesystem
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1320068350
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
Review Comment:
Cool. Let's update the comment then - it led me to believe that setting to an empty string was overloaded to delete the field.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1320393562
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
Review Comment:
It might be better to use the `Proxy` terminology for these (i.e., `Client::Request` and `Proxy::Request` rather than `ServerRequest`)? That's consistent with other terminology in ATS, such as log fields and traffic dumps.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
Review Comment:
Above we suggest using `auto` liberally. Should we do that in our examples for this, rather than explicitly declare `borrow`?
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
Review Comment:
Suggest: `A big part` -> `A big use case`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
Review Comment:
`; For` -> `; for`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
+latter will not exist on a cache miss, and should therefore only be used
+in callbacks involving origin transactions (*cache misses*).
Review Comment:
`will not exist on a cache miss` -> `will not exist on a cache hit`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
+latter will not exist on a cache miss, and should therefore only be used
+in callbacks involving origin transactions (*cache misses*).
+
+Accessing the client connections is easily done with
+
+```
+borrow conn = Client::Connection::get();
+```
+
+TODO: More stuff here, explaining the details
+
+## 3.6. Overridable configurations
+In ATS, some (not all) configurations can be overriden per transaction, or
+remap rule. Cripts supports all such configurations, in a way that retains
+the naming from `records.config`! Examples:
+
+```
+proxy.config.http.cache.http.set(0);
+
+if (proxy.config.http.cache.generation.get() > 0) {
+ // Do something
+}
+```
+
+All overridable configurations are documented in the [records.config](https://docs.trafficserver.apache.org/en/latest/admin-guide/files/records.config.en.html)
+documentation. Look for a tag `Overridable` for each setting.
+
+## 3.7. Pattern and identity matching
+
+Several pattern matching features exists in Cripts today:
+
+| Name | Description |
+| ------------------ | ------------------------------------------------------------------------------- |
+| Matcher::Range::IP | Match an IP (from e.g. a `Client::Connection`) against a range of IPs |
+| Matcher::PCRE | Create a Perl compatible regular expression, to match arbitrary strings against |
+
+They all follow the same basic concept:
+
+1. Setup a matcher (ideally `static` for performance)
+2. Get the string or identity to match from the transaction
+3. Call the `contains()` (or `match()`, they are synonyms) function
+
+Examples:
+
+```
+static Matcher::Range::IP allow({"192.168.201.0/24", "17.0.0.0/8"});
+borrow conn = Client::Connection::get();
+
+if (allow.contains(conn.ip())) {
+ CDebug("Client IP allowed: {}", conn.ip().string(24, 64));
+ ...
+}
+```
+
+Again, it's important to use the `static` keyword here, which helps the Cripts compiler
+to optimize the creation of the Matcher.
+
+```
+static Matcher::PCRE pcre("^/([^/]+)/(.*)$");
+auto url = Client::URL::get();
+auto res = pcre.match(url.path);
+
+if (res) {
+ borrow resp = Client::Response::get()
+
+ resp["X-PCRE-Test"] = format("{} and {}", res[1], res[2]);
+}
+```
+
+## 3.8. Cryptography functions
+
+## 3.9. Various other utilities
+
+## 3.10. Transaction contexts
+### 3.10.1. Instance data (parameters)
+
+### 3.10.2. Transaction data
+
+# 4. Plugins Cript can mimic or replace
+
+This is a list of existing ATS plugins that properly written and configure Cript
+scripts could replace. This will repeat some of the sections
+and mentions above, but helps identifying what can be used and when.
+
+## 4.1. conf_remap
+
+This plugin can set overridable configuration per remap. Cripts supports that via
+the global `proxy.` object. E.g.
+
+```
+proxy.config.http.cache.http.set(1);
+
+if (proxy.config.http.cache.http.get() {
+ //...
+}
+```
+
+## 4.2. cachekey
+
+A Cript is free to modify the `Cache::URL`` as needed, in either `do_remap()` or
+`do_post_remap()`. We recommend the latter to be used for cache-key manipulation.
+
+```
+do_post_remap()
+{
+ borrow ckey = Cache::URL::get();
+
+ ckey.query.sort();
+ ckey.path += "entropy";
+}
+```
+
+## 4.3. header_rewrite
+
+Almost all features from `header_rewrite` are available, and more flexible, in Cript.
+If there's anything missing, please let us know.
+
+## 4.4. regex_remap
+
+Cript supports PCRE2, as well as modifying the request URI as you like. For example:
+
+```
+do_post_remap()
+{
+ static Matcher::PCRE hosts({"(.*(\\.ogre.\\.com"});
+ borrow url = Client::URL::get();
+ auto res = hosts.match(url.host);
+
+ if (res) {
+ url.path.insert(0, res[1]); // Prepend the path with the hostname
+ }
+}
+```
+
+## 4.5. geoip_acl and maxmind_acl
+
+Lookups into the geo-location database is done via the connection object
Review Comment:
Append with: `:`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
Review Comment:
We should should clarify here that we're referring to `Cript::string_view` rather than `std::string_view`. Elsewhere in this paragraph, `string` means `std::string`, so it would be natural for someone to assume `string_view` is simply the `std` version. Might want to say how `Cript::string_view` is different from the `std` as a user will be curious.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
Review Comment:
`clients` -> `client's`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
Review Comment:
I suggest `indexing` rather than `indexes`. If we stick with the plural of `index`, `indices` is more common in technical docs.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
Review Comment:
Might was well end these nice sentences with periods.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
Review Comment:
Probably good to fill this in. Same as the next block.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
Review Comment:
* `With this in mind,` -> `With these calls in place,`
* End with a `:`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
Review Comment:
This is cool.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
Review Comment:
* `: The` -> `: the`
* `client connections` -> `client connection`
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
Review Comment:
This applies to the other cript examples here too.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
+latter will not exist on a cache miss, and should therefore only be used
+in callbacks involving origin transactions (*cache misses*).
+
+Accessing the client connections is easily done with
+
+```
+borrow conn = Client::Connection::get();
+```
+
+TODO: More stuff here, explaining the details
+
+## 3.6. Overridable configurations
+In ATS, some (not all) configurations can be overriden per transaction, or
+remap rule. Cripts supports all such configurations, in a way that retains
+the naming from `records.config`! Examples:
+
+```
+proxy.config.http.cache.http.set(0);
+
+if (proxy.config.http.cache.generation.get() > 0) {
+ // Do something
+}
+```
Review Comment:
This is cool. I suggest giving a `set()` example.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
+latter will not exist on a cache miss, and should therefore only be used
+in callbacks involving origin transactions (*cache misses*).
+
+Accessing the client connections is easily done with
+
+```
+borrow conn = Client::Connection::get();
+```
+
+TODO: More stuff here, explaining the details
+
+## 3.6. Overridable configurations
+In ATS, some (not all) configurations can be overriden per transaction, or
+remap rule. Cripts supports all such configurations, in a way that retains
+the naming from `records.config`! Examples:
+
+```
+proxy.config.http.cache.http.set(0);
+
+if (proxy.config.http.cache.generation.get() > 0) {
+ // Do something
+}
+```
+
+All overridable configurations are documented in the [records.config](https://docs.trafficserver.apache.org/en/latest/admin-guide/files/records.config.en.html)
+documentation. Look for a tag `Overridable` for each setting.
+
+## 3.7. Pattern and identity matching
+
+Several pattern matching features exists in Cripts today:
+
+| Name | Description |
+| ------------------ | ------------------------------------------------------------------------------- |
+| Matcher::Range::IP | Match an IP (from e.g. a `Client::Connection`) against a range of IPs |
+| Matcher::PCRE | Create a Perl compatible regular expression, to match arbitrary strings against |
+
+They all follow the same basic concept:
+
+1. Setup a matcher (ideally `static` for performance)
+2. Get the string or identity to match from the transaction
+3. Call the `contains()` (or `match()`, they are synonyms) function
+
+Examples:
+
+```
+static Matcher::Range::IP allow({"192.168.201.0/24", "17.0.0.0/8"});
+borrow conn = Client::Connection::get();
+
+if (allow.contains(conn.ip())) {
+ CDebug("Client IP allowed: {}", conn.ip().string(24, 64));
+ ...
+}
+```
+
+Again, it's important to use the `static` keyword here, which helps the Cripts compiler
+to optimize the creation of the Matcher.
+
+```
+static Matcher::PCRE pcre("^/([^/]+)/(.*)$");
+auto url = Client::URL::get();
+auto res = pcre.match(url.path);
+
+if (res) {
+ borrow resp = Client::Response::get()
+
+ resp["X-PCRE-Test"] = format("{} and {}", res[1], res[2]);
+}
+```
+
+## 3.8. Cryptography functions
+
+## 3.9. Various other utilities
+
+## 3.10. Transaction contexts
+### 3.10.1. Instance data (parameters)
+
+### 3.10.2. Transaction data
+
+# 4. Plugins Cript can mimic or replace
+
+This is a list of existing ATS plugins that properly written and configure Cript
+scripts could replace. This will repeat some of the sections
+and mentions above, but helps identifying what can be used and when.
+
+## 4.1. conf_remap
+
+This plugin can set overridable configuration per remap. Cripts supports that via
+the global `proxy.` object. E.g.
+
+```
+proxy.config.http.cache.http.set(1);
+
+if (proxy.config.http.cache.http.get() {
+ //...
+}
+```
+
+## 4.2. cachekey
+
+A Cript is free to modify the `Cache::URL`` as needed, in either `do_remap()` or
Review Comment:
There's an extra \` after `URL`.
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
+
+Note that not all of these are available in every callback; For example, the client
+response header is not available to read or write until we are in the hook for
+`do_send_response()`.
+
+The response headers has a couple of additional features specifically for
+responses:
+```
+borrow client_resp = Client::Response::get();
+
+if (resp.status = 220) {
+ resp.status = 200;
+}
+
+// TBD more stuff here ?
+```
+
+Similarly, the request headers has a few unique traits as well:
+
+```
+borrow client_req = Client::Request::get();
+
+if (client_req.method == "GET") {
+ ...
+}
+
+// TBD more stuff here ?
+```
+
+## 3.4. Processing and modifying URLs
+
+Similarly to headers, URLs are important in Cripts, in all its various forms.
+Currently, Cript supports the following URLs:
+
+| URL name | Description |
+| ---------------- | -------------------------------------------------------------- |
+| Client::Pristine | The pristine client request URL, which is immutable |
+| Client::URL | The clients request URL, which can be modified |
+| Cache::URL | This is a special URL, used internally of ATS as the cache key |
+
+Getting these URLs follows a similar getter pattern to the headers:
+```
+borrow pristine = Pristine::URL::get();
+borrow client = Client::URL::get();
+borrow cache = Cache::URL::get();
+```
+
+Within a URL object, you can access all its various components via names following
+standard URL naming.
+
+| Identifier | Description |
+| ---------- | --------------------------------------- |
+| host | The URL host |
+| port | The URL port number |
+| path | The URL path |
+| query | The URL query parameters (all of them!) |
+
+Using this is easy (of course):
+```
+auto url = Client::URL;
+
+if (url.host == "www.example.com") {
+ ...
+}
+```
+
+The `path` components does support indexes, e.g. the first URL path
+component ("directory") can be read or written with `path[0]`.
+
+The query parameter has a set of additional features, which are particularly
+useful for modifying the cache key URLs. This includes sorting the list of
+query parameters, or adding and removing a query parameter by name. This is
+best explained with a real example:
+
+```
+borrow client_req = Client::Request::get();
+borrow c_url = Cache::URL::get();
+
+c_url.query.sort(); // Sorts all query parameter by name first
+c_url.query["foo"].erase(); // Removes the foo query parameter, if it exists
+c_url.query["bar"] = "fie"; // Adds, or modifies, the bar query param to be "fie"
+
+if (client_req["X-Miles"]) {
+ c_url.path += "key_add=";
+ c_url.path += client_req["X-Miles"]; // Adds this header to the cache key
+}
+```
+
+With this in mind, a URL query path of
+
+```
+?foo=fum&z=xxx&d=yyy
+```
+
+gets normalized and modified to
+
+```
+?bar=fie&d=yyy&z=xxx
+```
+
+In addition, the cache key URL path is appended with an additional string
+extracted from the request headers.
+
+### 3.4.1. Special case: Cache Key URL
+
+## 3.5. Accessing and modifying connections
+
+There are essentially two possible connections being involved with a
+transaction: The client connections, and the origin server connection. The
+latter will not exist on a cache miss, and should therefore only be used
+in callbacks involving origin transactions (*cache misses*).
+
+Accessing the client connections is easily done with
Review Comment:
End with a `:`
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1686764468
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1686722643
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] ezelkow1 commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "ezelkow1 (via GitHub)" <gi...@apache.org>.
ezelkow1 commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1693506646
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316382747
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
Review Comment:
The bundles is something I added fairly recently, and are not mentioned in the README. It will need to be documented. And yes, they are "chains", the idea is that a Bundle can add as much as it wants, and it is responsible for validations etc.
The power of the bundles is to make very common tasks really easy to activate. This reduces the size of each script. The bundles are a little bit less efficient than explicitly writing the callback ("hook"), because the hooks are setup and preparared at compile time, whereas bundles are at runtime. So there's an indirection / pointer access for the bundles, which doesn't happen when you do "raw" callbacks.
You can mix bundles and callbacks as well, the bundles are evaluated first, and then the callbacks. Which means, you can override a bundle if needed.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1323601825
##########
src/cripts/README.md:
##########
@@ -0,0 +1,453 @@
+# 1. Cripts
+
+Cripts, C-Scripts, is a set of wrappers and include files, for making simple ATS
+plugins easy to generate, modify or create from scratch. A key design here is that
+the Code is the Configuration, i.e. the intent really is to have a custom Cript file
+for every remap rule in the running system.
+
+ToDo: This document is not 100% updated with all features, but is at least a starting point.
+
+- [1. Cripts](#1-cripts)
+- [2. Building Cripts](#2-building-cripts)
+ - [2.1. Building a Cript](#21-building-a-cript)
+ - [2.2. Lint: Validating a Cript](#22-lint-validating-a-cript)
+ - [2.3. Clang-tidy](#23-clang-tidy)
+- [3. Writing Cripts](#3-writing-cripts)
+ - [3.1. Data types](#31-data-types)
+ - [3.2. Hooks](#32-hooks)
+ - [3.3. Processing and modifying headers](#33-processing-and-modifying-headers)
+ - [3.4. Processing and modifying URLs](#34-processing-and-modifying-urls)
+ - [3.4.1. Special case: Cache Key URL](#341-special-case-cache-key-url)
+ - [3.5. Accessing and modifying connections](#35-accessing-and-modifying-connections)
+ - [3.6. Overridable configurations](#36-overridable-configurations)
+ - [3.7. Pattern and identity matching](#37-pattern-and-identity-matching)
+ - [3.8. Cryptography functions](#38-cryptography-functions)
+ - [3.9. Various other utilities](#39-various-other-utilities)
+ - [3.10. Transaction contexts](#310-transaction-contexts)
+ - [3.10.1. Instance data (parameters)](#3101-instance-data-parameters)
+ - [3.10.2. Transaction data](#3102-transaction-data)
+- [4. Plugins Cript can mimic or replace](#4-plugins-cript-can-mimic-or-replace)
+ - [4.1. conf\_remap](#41-conf_remap)
+ - [4.2. cachekey](#42-cachekey)
+ - [4.3. header\_rewrite](#43-header_rewrite)
+ - [4.4. regex\_remap](#44-regex_remap)
+ - [4.5. geoip\_acl and maxmind\_acl](#45-geoip_acl-and-maxmind_acl)
+ - [4.6. tcpinfo](#46-tcpinfo)
+
+# 2. Building Cripts
+
+Cripts needs the `{fmt}` and `PCRE2` libraries and include files. We currently only
+build cripts when explicitly enabled, and only using `cmake``.
+
+## 2.1. Building a Cript
+
+At the moment, building Cripts is the same as building any other ATS plugin, using
+either existing build system or tooling such as `tsxs`.
+
+```
+tsxs -lcript -o cript_test.so cript_test.cc
+```
+
+This will read the Cript file cript_test.cc and produce a cript_test.so plugin, that can be
+loaded in ATS via remap.config:
+
+```
+map https://example.com https://origin.example.com @plugin=cript_test.so
+```
+
+## 2.2. Lint: Validating a Cript
+
+TBD: I have the beginning of this tool, will land it later.
+
+## 2.3. Clang-tidy
+
+A custom clang-tidy configuration is provided with this patch, and I've run all
+code through clang-tidy with this configuration.
+
+# 3. Writing Cripts
+
+Cripts follow the same basic model of how ATS splits up transaction processing
+into what we call "hooks". A hook is essentially a callback mechanism, where
+custom code can be injected into the ATS core via plugins.
+
+The Cript language itself is essentially C++17, except it imposes some serious,
+but important, limitations on what can and can not be used. Albeit we call this
+a scripting language, it's truly compiled into regular, reloadable ATS plugins.
+
+To start off with, we'll show a very basic Cript, to get an idea of what to
+expect:
+
+```
+// The primary include file, this has to always be included
+#include <Cript/Preamble.hpp>
+
+do_send_response()
+{
+ borrow req = Client::Request::get();
+ borrow resp = Client::Response::get();
+
+ if (req["X-Miles"] != "") {
+ resp["X-Miles"] = req["X-Miles"]; // Echo back the request header
+ }
+}
+
+do_remap()
+{
+ borrow req = Client::Request::get();
+
+ req["@receipt"] = "PropertyX";
+}
+
+#include <Cript/Epilogue.hpp>
+```
+
+Don't worry about the exact details here, we will discuss them all further
+down this documentation. There are however two critical pieces here to remember:
+
+* All Cript's must have the Preamble and Epilogue include's as above
+* You can have your own C/C++ function definitions if you like, but the predefined
+ callbacks (such as `do_remap()`) have fixed names
+
+## 3.1. Data types
+
+Cript will make a best-effort to hide data types from the users as much as possible.
+As such, it's highly recommended to use the "auto" style when declaring variables.
+Cript being C/C++, it's impossible to hide everything, and to optimize integration
+with ATS, we have a few quirks.
+
+For example, there are two types of strings which can be returned, regular `strings`
+and something called `string_view`. The latter are immutable representations of
+strings that are owned and managed by ATS, and you can and should only use these
+when reading values out of say a request or request header.
+
+These are the typical types that are used by Cripts:
+
+| Type | Description |
+| ----------- | --------------------------------------------- |
+| string | This is the common std::string type from C++ |
+| string_view | An immutable, ATS owned string representation |
+| integer | A signed integer value, 64-bit long |
+| float | A signed, floating point value |
+| boolean | A `true` or `false` flag |
+
+## 3.2. Hooks
+
+To simplify usage, Cript predefines a set of function names, each corresponding
+to an ATS hook. These names are set in stone, and will be automatically added
+to the ATS core if provided in the Cript. Those hooks not used will not be
+called, obviously.
+
+The current version of Cript supports the following callbacks / hooks, all of which are optional:
+
+| Callback name | Hook equivalent | Description |
+| ------------------ | ------------------------------ | -------------------------------------------------- |
+| do_remap() | none | This is the main entry point for all remap plugins |
+| do_post_remap() | TS_HTTP_POST_REMAP_HOOK | Called right after the remap rule is done |
+| do_send_request() | TS_HTTP_SEND_REQUEST_HDR_HOOK | Called before making an origin request |
+| do_read_response() | TS_HTTP_READ_RESPONSE_HDR_HOOK | Called when the origin has a response |
+| do_send_response() | TS_HTTP_SEND_RESPONSE_HDR_HOOK | Called before sending a response to client |
+| do_txn_close() | TS_HTTP_TXN_CLOSE_HOOK | Called just before the transaction is done |
+
+Note that not all of these callbacks are triggered for all requests. For example,
+upon a cache hit in ATS, `do_send_request()` and `do_read_response()` are not called.
+In addition, there are two plugin specific callbacks, which are used when loading
+the plugins and instantiating remap rules:
+
+| Callback name | API equivalent | Description |
+| ------------------ | --------------------- | ---------------------------------------------- |
+| do_init | TSRemapInit() | Called once when the Cript is loaded |
+| do_create_instance | TSRemapNewInstance | Called for every remap rule using the Cript |
+| do_delete_instance | TSRemapDeleteInstance | Called to cleanup any instance data from above |
+
+## 3.3. Processing and modifying headers
+
+A big part of all Cripts is to read and modify various headers. ATS as it works,
+has four distinct headers, which translates into the following four environments:
+
+| Header name | Description |
+| ---------------- | -------------------------------------------------- |
+| Client::Request | The clients request header |
+| Client::Response | The response header that is sent to the client |
+| Server::Request | The request header being sent to the origin server |
+| Server::Response | The response header being received from origin |
+
+Accessing these headers is easy:
+```
+ borrow client_req = Client::Request::get();
+ borrow client_resp = Client::Response::get();
+ borrow server_req = Server::Request::get();
+ borrow server_resp = Server::Response::get();
+```
Review Comment:
The README.md has not been updated since I first did this, which is why I didn't include it to begin with. But then people wanted something. I'm not going to write a ton of documentation until we decide to actually land and use this :).
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] traeak commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "traeak (via GitHub)" <gi...@apache.org>.
traeak commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1721621972
are we okay with the .hpp extensions for the headers in include/cripts ?
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop merged pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop merged PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316384698
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
Review Comment:
Yeh, so the concept of instances was added after Cripts was initially done. It was really done to make it possible to write regular remap plugins taking @pparam options. My vision was that for the normal case, when Cripts are integrated into your deployment system, you wouldn't use instance data but rather generate a Cript which is both the code and the configuration. I.e. no @pparam options in remap.config.
The instance data is a std::array of a type that can hold int, float, string, ptr's etc. This is a "power user" feature (plugin writers), and not as user friendly as most of Cripts.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1316391421
##########
example/cripts/example1.cc:
##########
@@ -0,0 +1,242 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+// The primary include file, this has to always be included
+#include <cripts/Preamble.hpp>
+
+#include <cripts/Bundles/Common.hpp>
+
+// Globals for this Cript
+static Matcher::Range::IP CRIPT_ALLOW({"192.168.201.0/24", "10.0.0.0/8"});
+
+// This is called only when the plugin is initialized
+do_init()
+{
+ TSDebug("Cript", "Hello, example1 plugin is being initialized");
+}
+
+do_create_instance()
+{
+ instance.metrics[0] = Metrics::Sum::create("cript.example1.c0");
+ instance.metrics[1] = Metrics::Sum::create("cript.example1.c1");
+ instance.metrics[2] = Metrics::Sum::create("cript.example1.c2");
+ instance.metrics[3] = Metrics::Sum::create("cript.example1.c3");
+ instance.metrics[4] = Metrics::Sum::create("cript.example1.c4");
+ instance.metrics[5] = Metrics::Sum::create("cript.example1.c5");
+ instance.metrics[6] = Metrics::Sum::create("cript.example1.c6");
+ instance.metrics[7] = Metrics::Sum::create("cript.example1.c7");
+ instance.metrics[8] = Metrics::Sum::create("cript.example1.c8"); // This one should resize() the storage
+
+ Bundle::Common::activate().dscp(10).cache_control("max-age=259200");
+}
+
+do_txn_close()
+{
+ borrow conn = Client::Connection::get();
+
+ conn.pacing = Cript::Pacing::Off;
+ CDebug("Cool, TXN close also works");
+}
+
+do_send_request()
+{
+ borrow req = Server::Request::get();
+
+ req["X-Leif"] = "Meh";
+}
+
+do_read_response()
+{
+ borrow resp = Server::Response::get();
+
+ resp["X-DBJ"] = "Vrooom!";
+}
+
+do_send_response()
+{
+ borrow resp = Client::Response::get();
+ borrow conn = Client::Connection::get();
+ string msg = "Eliminate TSCPP";
+
+ resp["Server"] = ""; // Deletes the Server header
+ resp["X-AMC"] = msg; // New header
+ resp["Cache-Control"] = "Private"; // Deletes old CC values, and sets a new one
+ resp["X-UUID"] = UUID::Unique::get();
+ resp["X-tcpinfo"] = conn.tcpinfo.log();
+ resp["X-Cache-Status"] = resp.cache;
+ resp["X-Integer"] = 666;
+ resp["X-Data"] = AsString(txn_data[2]);
+
+ resp["X-ASN"] = conn.geo.ASN();
+ resp["X-ASN-Name"] = conn.geo.ASNName();
+ resp["X-Country"] = conn.geo.Country();
+ resp["X-ISO-Country"] = conn.geo.CountryCode();
+
+ // Setup some connection parameters
+ conn.congestion = "bbr";
+ conn.dscp = 8;
+ conn.pacing = 100000;
+
+ // Some file operations (note that the paths aren't required here, can just be strings, but it's a good practice)
+ static const File::Path p1("/tmp/foo");
+ static const File::Path p2("/tmp/secret.txt");
+
+ if (File::Status(p1).type() == File::Type::regular) {
+ resp["X-Foo-Exists"] = "yes";
+ } else {
+ resp["X-Foo-Exists"] = "no";
+ }
+
+ string secret = File::Line::Reader(p2);
+ CDebug("Read secret = {}", secret);
+
+ if (resp.status == 200) {
+ resp.status = 222;
+ }
+
+ borrow url2 = Cache::URL::get();
+
+ CDebug("Cache URL: {}", url2.url());
+ CDebug("Cache Host: {}", url2.host);
+ CDebug("Txn count: {}", conn.count());
+}
+
+do_remap()
+{
+ auto now = Time::Local::now();
+ borrow req = Client::Request::get();
+ borrow conn = Client::Connection::get();
+ auto ip = conn.ip();
+
+ if (CRIPT_ALLOW.contains(ip)) {
+ CDebug("Client IP allowed: {}", ip.string(24, 64));
+ }
+
+ CDebug("Epoch time is {} (or via .epoch(), {}", now, now.epoch());
+ CDebug("Year is {}", now.year());
+ CDebug("Month is {}", now.month());
+ CDebug("Day is {}", now.day());
+ CDebug("Hour is {}", now.hour());
+ CDebug("Day number is {}", now.yearday());
+
+ CDebug("from_url = {}", instance.from_url.c_str());
+ CDebug("to_url = {}", instance.to_url.c_str());
+
+ // Turn off the cache for testing
+ // proxy.config.http.cache.http.set(1);
+ // control.cache.nostore.set(true);
Review Comment:
That is correct. It builds the .hpp file by examining the overridable files, so it's part of the builds. If you add more overridable variables, they become available here as well.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] zwoop commented on a diff in pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on code in PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#discussion_r1296506562
##########
example/cripts/CMakeLists.txt:
##########
@@ -0,0 +1,51 @@
+# ##############################################################################
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with this work for
+# additional information regarding copyright ownership. The ASF licenses this
+# file to you under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+#
+# ##############################################################################
+
+# Todo: It'd be useful to build all Cripts that are put into this directory,
+# using GLOB etc. like this:
+# file(GLOB CRIPTS_EXAMPLES ${PROJECT_SOURCE_DIR}/example/cripts/*.cc)
+#
+# foreach(EXA ${CRIPTS_EXAMPLES})
+# get_filename_component(EXA ${EXA} NAME_WLE)
+# ....
+# endforeach()
+
+add_atsplugin(cripts_example1 example1.cc)
+
+target_include_directories(cripts_example1 PRIVATE "${PROJECT_SOURCE_DIR}/include")
+target_link_libraries(cripts_example1 PRIVATE ts::cripts)
+
+# This is a hack, but useful to run clang-tidy across all of Cripts
+# Todo: why is this not working??
+#find_package(fmt 8.1 REQUIRED)
+#$<TARGET_PROPERTY:fmt::fmt,INCLUDE_DIRECTORIES>
+
Review Comment:
It was supposed to find the include directories needed I think. I worked around it, but left it there for someone smart to fix it.
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficserver] bneradt commented on pull request #10191: Import of the Cripts scripting / plugin wrapper library and includes
Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #10191:
URL: https://github.com/apache/trafficserver/pull/10191#issuecomment-1686758429
[approve ci]
--
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: github-unsubscribe@trafficserver.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org