juanthropic opened a new pull request, #14025:
URL: https://github.com/apache/trafficserver/pull/14025

   Keying on headers, cookies, or a cleaned-up URL today means writing
   `run-plugin cachekey.so` lines by hand. When the key differs per host or
   path, every branch repeats the full flag list, and nothing checks that
   the flags agree or that a later REMAP rule doesn't change what the key
   reads. This adds a `CACHEKEY` section that only describes the key, and
   lets the compiler write the cachekey.so lines.
   
       REMAP {
           if geo.COUNTRY == "CN" {
               inbound.req.@Geo-Country = "{geo.COUNTRY}";
           }
       }
   
       CACHEKEY {
           cache.url.query.sort();
           cache.key.headers.add("Origin", "@Geo-Country");
           cache.key.cookies.exists("session");
   
           if inbound.req.Host == "api.example.com" {
               cache.key.cookies.add("locale");
           }
       }
   
   How it lowers:
   
   - The section runs on the remap hook, after every REMAP section, so the
     key sees REMAP's edits. It emits one `run-plugin cachekey.so` per
     branch of its if/elif/else chain, so exactly one instance runs per
     request. Statements outside the chain go into every branch.
   - `cache.*` statements map to cachekey.so flags: `cache.url.query.*`,
     `cache.url.path`, `cache.url.pristine()`, `cache.url.canonical()`,
     `cache.key.prefix`, `cache.key.headers.add()`,
     `cache.key.cookies.add()`.
   - `cache.key += "{expr}"` keys on a computed value through a numbered
     `@` header (capped at 99 parts).
   - `cache.key.headers.exists()` and `cache.key.cookies.exists()` key on
     presence, not value, through an `@` header named after the name.
   - `cache.bypass()` skips the cache from REMAP.
   - Every line sets `--key-type=cache_key,parent_selection_url`, so
     consistent-hash parent selection follows the cache key. This differs
     from cachekey.so's default, and the docs say so.
   - Conflicting statements (for example `query.keep()` with
     `query.remove()`), a `break` or a hand-written cachekey.so line next to
     a CACHEKEY section, and non-static names are compile errors that
     point at the statement.
   
   Docs are in `hrw4u.en.rst` and the README; the LSP knows the new
   statements. Tests: golden cases in `tests/data/cachekey/` plus unit
   tests.
   
   This is draft, some known gaps yet to be addressed:
   
   - Needs a rebase onto master: it conflicts with the switch to Ruff
     (#13643).
   - The sandbox policy checks the `run-plugin` and added `else`, but not
     the `set-header` operators and header or cookie conditions the
     lowering emits for `exists()` and `cache.key +=`.
   - The rst doesn't list `exists()` yet.
   - Sema doesn't support CACHEKEY yet; the front-end parity tests xfail
     for these inputs.
   - `exists("@X")` is rejected today; it will use a `@Hrw4u-Internal-`
     header.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to