Skip to content

Expose headless header/cookie DSL variables - #7573

Open
Mzack9999 wants to merge 1 commit into
devfrom
3796-headless-headers
Open

Expose headless header/cookie DSL variables#7573
Mzack9999 wants to merge 1 commit into
devfrom
3796-headless-headers

Conversation

@Mzack9999

@Mzack9999 Mzack9999 commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

Summary by CodeRabbit

  • New Features

    • Added access to response headers through both header and all_headers variables.
    • Added normalized header and cookie values for use in templates, matching, and extraction.
    • Added support for response status codes as a runtime variable.
    • Combined repeated header values into a single space-delimited value.
  • Bug Fixes

    • Ensured missing responses do not populate runtime variables.
    • Added consistent handling of all_headers wherever header matching is supported.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The headless protocol now extracts normalized response headers and cookies, exposes aggregate headers and status codes, and supports all_headers as a DSL alias for header.

Changes

Headless response variables

Layer / File(s) Summary
Response extraction and integration
pkg/protocols/headless/engine/headers.go, pkg/protocols/headless/engine/page.go, pkg/protocols/headless/engine/headers_test.go
Response headers and cookies are normalized into DSL variables, aggregate headers and status codes are stored, and extraction behavior is tested for nil and multi-value responses.
DSL header aliases and definitions
pkg/protocols/headless/headless.go, pkg/protocols/headless/operators.go, pkg/protocols/headless/operators_test.go
Runtime definitions include header variables, while all_headers resolves to the same header content as header in matching and extraction.

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
Loading

Suggested reviewers: dogancanbakir, dwisiswant0

Poem

A rabbit hops through headers bright,
With cookies tucked away just right.
header and all_headers cheer,
While status codes appear near.
DSL carrots grow tonight! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: exposing headless header and cookie DSL variables.
Linked Issues check ✅ Passed The PR exposes response headers as DSL variables for headless matchers and extractors, matching the linked issue's request.
Out of Scope Changes check ✅ Passed The added cookie and normalized response-variable support aligns with the PR objective and supports the header-variable feature.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 3796-headless-headers

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d81cc3 and 3d52c73.

📒 Files selected for processing (6)
  • pkg/protocols/headless/engine/headers.go
  • pkg/protocols/headless/engine/headers_test.go
  • pkg/protocols/headless/engine/page.go
  • pkg/protocols/headless/headless.go
  • pkg/protocols/headless/operators.go
  • pkg/protocols/headless/operators_test.go

Comment on lines +16 to +21
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, " ")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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 as Status-Code and Data.
📍 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.

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.

Expose header key: value as protocol response variable in headless protocol

1 participant