Skip to content

[core] Implement <esi:vars> and $\(...\) expression evaluation#267

Merged
s2x merged 1 commit into
mainfrom
feat/esi-vars-164
May 18, 2026
Merged

[core] Implement <esi:vars> and $\(...\) expression evaluation#267
s2x merged 1 commit into
mainfrom
feat/esi-vars-164

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented May 18, 2026

Summary

Implements <esi:vars> block parsing and $(...) expression evaluation for ESI variable substitution.

Closes #164

Changes

mesi/config.go

  • Added Variables map[string]string — holds ESI variable definitions from <esi:vars> blocks and pre-populated values
  • Added RequestHeaders http.Header — for $(HTTP_HEADER{Name}) resolution
  • Added RequestCookies map[string]string — for $(HTTP_COOKIE{name}) resolution
  • Added RequestQuery map[string]string — for $(QUERY_STRING{param}) resolution

mesi/vars.go (new)

  • evaluateExpression(expr, config) — resolves $(...) patterns:
    • $(NAME) → looks up in config.Variables (explicit variables take precedence)
    • $(HTTP_HEADER{Name}) → resolves from config.RequestHeaders
    • $(HTTP_COOKIE{name}) → resolves from config.RequestCookies
    • $(QUERY_STRING{param}) → resolves from config.RequestQuery
    • Undefined → empty string
  • parseVarsBlock(rawContent) — extracts <esi:variable name="..." value="..."/> definitions from <esi:vars> blocks

mesi/parser.go

  • Process vars tokens inline: parse variables, merge into config, emit empty output
  • Apply evaluateExpression to static text content
  • Apply evaluateExpression to include src and alt attributes before fetching

Tests

  • TestEvaluateExpression (15 cases): variable substitution, HTTP_HEADER, HTTP_COOKIE, QUERY_STRING, precedence
  • TestParseVarsBlock (7 cases): parsing variable definitions
  • TestMESIParseWithVarsAndTextSubstitution (6 cases): end-to-end text substitution
  • TestMESIParseWithVarsAndInclude: include src resolution
  • TestMESIParseWithVarsBlockAndInclude: vars block + include
  • TestMESIParseWithVarsIncludeUsingBACKEND: full URL variable
  • TestMESIParseWithVarsAltAttribute: alt attribute resolution
  • TestMESIParseVarsAndTemplatedURL: multiple $(...) in one URL
  • E2E fixture 11-esi-vars.html: text substitution via <esi:vars> block

Documentation

  • Updated docs/features.md: <esi:vars> / $(...) marked as ✅ (was ⚠️)
  • Added note explaining variable substitution support

- Add Variables, RequestHeaders, RequestCookies, RequestQuery to EsiParserConfig
- Create vars.go with evaluateExpression and parseVarsBlock
- Parse <esi:vars> blocks to extract variable definitions
- Apply $(NAME) substitution to static text content and include src/alt
- Support $(HTTP_HEADER{Name}), $(HTTP_COOKIE{name}), $(QUERY_STRING{param})
- Add comprehensive unit tests (28 test cases)
- Add E2E test fixture for variable substitution
- Update feature matrix in docs/features.md
@s2x s2x merged commit 6e9ef48 into main May 18, 2026
4 checks passed
@s2x s2x deleted the feat/esi-vars-164 branch May 18, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[core] Implement <esi:vars> and $(...) expression evaluation

1 participant