Skip to content

[SDK] Add Changes to Clone Downstream and Upstream Header Contexts#2631

Merged
renuka-fernando merged 5 commits into
wso2:mainfrom
SavinduDimal:sdk-header-clone
Jul 21, 2026
Merged

[SDK] Add Changes to Clone Downstream and Upstream Header Contexts#2631
renuka-fernando merged 5 commits into
wso2:mainfrom
SavinduDimal:sdk-header-clone

Conversation

@SavinduDimal

Copy link
Copy Markdown
Contributor

Purpose

Description

This pull request introduces support for immutable snapshots of original client request and upstream response headers in both the Go and Python SDKs. These snapshots, represented by new DownstreamContext and UpstreamContext types, are now available in all policy context objects, allowing policies to access unchanged headers.

New Context Types and Header Snapshots:

  • Added DownstreamContext and UpstreamContext types to both Go (context.go) and Python (types.py) SDKs, each holding immutable copies of original client request and upstream response headers, respectively. [1] [2]
  • Updated all request, response, and streaming context structs/classes (e.g., RequestHeaderContext, ResponseHeaderContext, RequestStreamContext, etc.) to include optional downstream and upstream fields referencing these new context types. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

Python SDK Integration:

  • Registered DownstreamContext and UpstreamContext in the Python SDK’s __init__.py and __all__ to ensure they are exported and available for import. [1] [2] [3]

Backward Compatibility:

  • Documented that these fields may be None (Python) or nil (Go) on older gateways, and policies should fall back to legacy header validation if unavailable. [1] [2]

These changes improve policy reliability by allowing access to original, unmodified headers, while maintaining backward compatibility with older gateway versions.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Go and Python policy SDKs add downstream request and upstream route/response snapshot types. These snapshots are exposed through request, response, and streaming context structures, with Python public exports updated and the legacy Go upstream field deprecated.

Changes

Gateway header context snapshots

Layer / File(s) Summary
Snapshot types and exports
sdk/core/policy/v1alpha2/context.go, sdk-python/src/apip_sdk_core/policy/v1alpha2/types.py, sdk-python/src/apip_sdk_core/policy/v1alpha2/__init__.py
Adds downstream and upstream snapshot data structures and exports the new Python types.
Request context fields
sdk/core/policy/v1alpha2/context.go, sdk-python/src/apip_sdk_core/policy/v1alpha2/types.py
Adds optional downstream and upstream snapshots to request-phase contexts and deprecates the Go UpstreamInfo field.
Response context fields
sdk/core/policy/v1alpha2/context.go, sdk-python/src/apip_sdk_core/policy/v1alpha2/types.py
Adds optional downstream and upstream snapshots to response and streaming response contexts.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: malinthaprasan, pubudu538, lasanthas

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers purpose and implementation, but most required template sections like Goals, Tests, Security, and Environment are missing. Add the missing template sections: Goals, Approach, User stories, Documentation, Automation tests, Security checks, Samples, Related PRs, and Test environment.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the PR's main change: adding downstream and upstream header context snapshots to the SDKs.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 `@sdk-python/src/apip_sdk_core/policy/v1alpha2/types.py`:
- Around line 132-153: Make the headers fields in DownstreamContext and
UpstreamContext nullable to match the documented unavailable-state behavior and
the Go SDK contract. Update both annotations and defaults so instances can
represent None rather than always constructing Headers(), while preserving the
existing context classes and docstrings.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8e28d677-516c-4bc1-822e-7da2b72469d3

📥 Commits

Reviewing files that changed from the base of the PR and between 61ed191 and 1f365f7.

📒 Files selected for processing (3)
  • sdk-python/src/apip_sdk_core/policy/v1alpha2/__init__.py
  • sdk-python/src/apip_sdk_core/policy/v1alpha2/types.py
  • sdk/core/policy/v1alpha2/context.go

Comment thread sdk-python/src/apip_sdk_core/policy/v1alpha2/types.py
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 13, 2026
@github-actions

This comment was marked as outdated.

@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 @.github/workflows/sdk-ai-release.yml:
- Around line 4-6: Safely handle the manual version input in
.github/workflows/sdk-ai-release.yml lines 4-6,
.github/workflows/sdk-core-release.yml lines 4-6, and
.github/workflows/sdk-release.yml lines 4-6: pass inputs.version through an
environment variable rather than interpolating it into shell code, validate it
against strict semantic-version syntax before creating any tag, and use only the
validated value for subsequent release commands.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 398e2658-f176-4f62-b396-bb2b653a08af

📥 Commits

Reviewing files that changed from the base of the PR and between 1f365f7 and 3c9319e.

📒 Files selected for processing (3)
  • .github/workflows/sdk-ai-release.yml
  • .github/workflows/sdk-core-release.yml
  • .github/workflows/sdk-release.yml

Comment thread .github/workflows/sdk-ai-release.yml Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 20, 2026
Comment thread sdk/core/policy/v1alpha2/context.go
Refactor context types to improve clarity and consistency in upstream/downstream handling
Refactor context types to enhance clarity and consistency in downstream and upstream request handling
@renuka-fernando
renuka-fernando merged commit 05139c4 into wso2:main Jul 21, 2026
10 of 15 checks passed
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.

2 participants