[core] Implement <esi:vars> and $\(...\) expression evaluation#267
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements
<esi:vars>block parsing and$(...)expression evaluation for ESI variable substitution.Closes #164
Changes
mesi/config.goVariables map[string]string— holds ESI variable definitions from<esi:vars>blocks and pre-populated valuesRequestHeaders http.Header— for$(HTTP_HEADER{Name})resolutionRequestCookies map[string]string— for$(HTTP_COOKIE{name})resolutionRequestQuery map[string]string— for$(QUERY_STRING{param})resolutionmesi/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.RequestQueryparseVarsBlock(rawContent)— extracts<esi:variable name="..." value="..."/>definitions from<esi:vars>blocksmesi/parser.govarstokens inline: parse variables, merge into config, emit empty outputevaluateExpressionto static text contentevaluateExpressionto includesrcandaltattributes before fetchingTests
TestEvaluateExpression(15 cases): variable substitution, HTTP_HEADER, HTTP_COOKIE, QUERY_STRING, precedenceTestParseVarsBlock(7 cases): parsing variable definitionsTestMESIParseWithVarsAndTextSubstitution(6 cases): end-to-end text substitutionTestMESIParseWithVarsAndInclude: include src resolutionTestMESIParseWithVarsBlockAndInclude: vars block + includeTestMESIParseWithVarsIncludeUsingBACKEND: full URL variableTestMESIParseWithVarsAltAttribute: alt attribute resolutionTestMESIParseVarsAndTemplatedURL: multiple $(...) in one URL11-esi-vars.html: text substitution via<esi:vars>blockDocumentation
docs/features.md:<esi:vars>/$(...)marked as ✅ (was