Expose headless header/cookie DSL variables - #7573
Conversation
WalkthroughThe headless protocol now extracts normalized response headers and cookies, exposes aggregate headers and status codes, and supports ChangesHeadless response variables
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant HeadlessPage
participant addResponseVariables
participant DSLOperators
HeadlessPage->>addResponseVariables: extract response headers and cookies
addResponseVariables->>HeadlessPage: populate response data
HeadlessPage->>DSLOperators: provide header and all_headers values
DSLOperators->>DSLOperators: resolve all_headers as header
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/protocols/headless/engine/headers.go`:
- Around line 16-21: In pkg/protocols/headless/engine/headers.go lines 16-21,
prevent normalized cookie and header names from overwriting reserved or
already-populated event keys, and apply deterministic precedence when multiple
headers normalize to the same key. In pkg/protocols/headless/engine/page.go
lines 222-226, prevent dynamic injection from replacing the protocol-owned
aggregate headers or HTTP status fields; add regression coverage for collisions
including Status-Code and Data.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 06e63fcc-ef09-417c-9a0e-8b91a4dfcece
📒 Files selected for processing (6)
pkg/protocols/headless/engine/headers.gopkg/protocols/headless/engine/headers_test.gopkg/protocols/headless/engine/page.gopkg/protocols/headless/headless.gopkg/protocols/headless/operators.gopkg/protocols/headless/operators_test.go
| for _, cookie := range resp.Cookies() { | ||
| data[strings.ToLower(cookie.Name)] = cookie.Value | ||
| } | ||
| for k, v := range resp.Header { | ||
| k = strings.ToLower(strings.ReplaceAll(strings.TrimSpace(k), "-", "_")) | ||
| data[k] = strings.Join(v, " ") |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Define collision precedence for response-derived DSL variables.
Normalized headers and cookies currently write into the shared event map without protecting protocol-owned fields, so a target can spoof status_code, header, or data.
pkg/protocols/headless/engine/headers.go#L16-L21: preserve existing/reserved keys and deterministically handle multiple headers that normalize to one key.pkg/protocols/headless/engine/page.go#L222-L226: ensure dynamic injection cannot overwrite the actual aggregate headers or HTTP status; add regression coverage for colliding names such asStatus-CodeandData.
📍 Affects 2 files
pkg/protocols/headless/engine/headers.go#L16-L21(this comment)pkg/protocols/headless/engine/page.go#L222-L226
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/protocols/headless/engine/headers.go` around lines 16 - 21, In
pkg/protocols/headless/engine/headers.go lines 16-21, prevent normalized cookie
and header names from overwriting reserved or already-populated event keys, and
apply deterministic precedence when multiple headers normalize to the same key.
In pkg/protocols/headless/engine/page.go lines 222-226, prevent dynamic
injection from replacing the protocol-owned aggregate headers or HTTP status
fields; add regression coverage for collisions including Status-Code and Data.
Summary
key: valueas protocol response variable in headless protocol #3796Summary by CodeRabbit
New Features
headerandall_headersvariables.Bug Fixes
all_headerswherever header matching is supported.