Skip to content

feat: add case-insensitive helper methods for HTTP request headers and query parameters#1297

Merged
Pratham-Mishra04 merged 1 commit intov1.4.0from
01-09-chore_added_case-insensitive_helper_methods_for_header_and_query_parameter_lookups_in_httprequest
Jan 12, 2026
Merged

feat: add case-insensitive helper methods for HTTP request headers and query parameters#1297
Pratham-Mishra04 merged 1 commit intov1.4.0from
01-09-chore_added_case-insensitive_helper_methods_for_header_and_query_parameter_lookups_in_httprequest

Conversation

@Pratham-Mishra04
Copy link
Copy Markdown
Collaborator

Summary

Added case-insensitive helper methods for header and query parameter lookups in HTTPRequest to improve plugin development experience and consistency.

Changes

  • Added CaseInsensitiveHeaderLookup() and CaseInsensitiveQueryLookup() helper methods to the HTTPRequest struct
  • Implemented a shared caseInsensitiveLookup() function that handles various lookup scenarios
  • Updated the governance plugin to use these new helper methods
  • Updated documentation to recommend using these helper methods
  • Added changelog entry

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (Next.js)
  • Docs

How to test

Test the new helper methods with various header and query parameter cases:

# Core/Transports
go test ./core/schemas -run TestHTTPRequest_CaseInsensitiveLookup

# Test with a plugin that uses the new methods
go run cmd/bifrost/main.go run --plugin plugins/governance

Breaking changes

  • Yes
  • No

Related issues

Improves developer experience when working with HTTP headers and query parameters in plugins.

Security considerations

No security implications. This change only affects how headers and query parameters are accessed.

Checklist

  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 9, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added case-insensitive lookup methods for HTTP headers and query parameters to improve request handling regardless of header/parameter casing.
  • Documentation

    • Updated Go and WASM plugin guides to recommend and illustrate the new case-insensitive helpers and clarify header/query handling best practices.
  • Bug Fixes / Stability

    • Core components updated to use the new helpers for more robust header/query retrieval.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Added case-insensitive header and query lookup helpers to HTTPRequest, updated documentation to recommend those helpers, and refactored the governance plugin to use the new helpers instead of an internal lookup function.

Changes

Cohort / File(s) Summary
Core Implementation
core/schemas/plugin.go, core/changelog.md
Added CaseInsensitiveHeaderLookup and CaseInsensitiveQueryLookup methods on HTTPRequest and a private caseInsensitiveLookup helper; documented the change in core/changelog.md.
Documentation Updates
docs/plugins/writing-go-plugin.mdx, docs/plugins/writing-wasm-plugin.mdx
Replaced prior guidance about lowercasing maps with notes recommending case-insensitive helper usage; updated code examples to demonstrate helper calls.
Plugin Refactor
plugins/governance/main.go
Removed local case-insensitive lookup implementation; replaced header reads with req.CaseInsensitiveHeaderLookup(...) for keys like x-bf-vk, authorization, x-api-key, x-goog-api-key.

Sequence Diagram(s)

(omitted)

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I hopped through headers, found each key,
No matter how they came to be.
Queries and names, case set free,
A gentle helper guides me — whee! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main feature: adding case-insensitive helper methods for HTTP request headers and query parameters.
Description check ✅ Passed The description covers all major template sections including Summary, Changes, Type of change, Affected areas, How to test, Breaking changes, and Security considerations. The Checklist is mostly complete.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 01-09-chore_added_case-insensitive_helper_methods_for_header_and_query_parameter_lookups_in_httprequest

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @core/schemas/plugin.go:
- Line 46: The comment above the function incorrectly names it as
caseInsensitiveHeaderLookup; update the comment to reference the actual function
name caseInsensitiveLookup so the docstring matches the function identifier and
avoids confusion when locating caseInsensitiveLookup in the codebase.
🧹 Nitpick comments (1)
docs/plugins/writing-go-plugin.mdx (1)

244-246: Consider recommending lowercase keys when setting headers.

The example shows setting headers with mixed case (X-Custom-Header), but the HTTPRequest struct comments indicate that "keys are lowercase". For consistency and to ensure subsequent lookups work correctly, consider recommending lowercase keys when setting:

📝 Suggested clarification
-// For setting headers, use direct map access
-req.Headers["X-Custom-Header"] = "value"
+// For setting headers, use lowercase keys for consistency
+req.Headers["x-custom-header"] = "value"
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2968464 and a96208e.

📒 Files selected for processing (5)
  • core/changelog.md
  • core/schemas/plugin.go
  • docs/plugins/writing-go-plugin.mdx
  • docs/plugins/writing-wasm-plugin.mdx
  • plugins/governance/main.go
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

always check the stack if there is one for the current PR. do not give localized reviews for the PR, always see all changes in the light of the whole stack of PRs (if there is a stack, if there is no stack you can continue to make localized suggestions/reviews)

Files:

  • docs/plugins/writing-go-plugin.mdx
  • plugins/governance/main.go
  • core/changelog.md
  • core/schemas/plugin.go
  • docs/plugins/writing-wasm-plugin.mdx
🧠 Learnings (4)
📚 Learning: 2025-12-30T05:37:48.365Z
Learnt from: Pratham-Mishra04
Repo: maximhq/bifrost PR: 1180
File: docs/features/mcp/connecting-to-servers.mdx:452-458
Timestamp: 2025-12-30T05:37:48.365Z
Learning: When reviewing documentation PRs in a Graphite-managed stack, first check related or previous PRs in the stack for feature implementations before flagging documentation as incorrect or unsupported. Documentation MDX files often reference features implemented in earlier stack PRs; verify that the documented behavior exists in earlier changes and that the docs accurately reflect the implemented state before requesting edits.

Applied to files:

  • docs/plugins/writing-go-plugin.mdx
  • docs/plugins/writing-wasm-plugin.mdx
📚 Learning: 2025-12-09T17:07:42.007Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1006
File: core/schemas/account.go:9-18
Timestamp: 2025-12-09T17:07:42.007Z
Learning: In core/schemas/account.go, the HuggingFaceKeyConfig field within the Key struct is currently unused and reserved for future Hugging Face inference endpoint deployments. Do not flag this field as missing from OpenAPI documentation or require its presence in the API spec until the feature is actively implemented and used. When the feature is added, update the OpenAPI docs accordingly; otherwise, treat this field as non-breaking and not part of the current API surface.

Applied to files:

  • plugins/governance/main.go
  • core/schemas/plugin.go
📚 Learning: 2025-12-29T11:54:55.836Z
Learnt from: akshaydeo
Repo: maximhq/bifrost PR: 1153
File: framework/configstore/rdb.go:2221-2246
Timestamp: 2025-12-29T11:54:55.836Z
Learning: In Go reviews, do not flag range-over-int patterns like for i := range n as compile-time errors, assuming Go 1.22+ semantics. Only flag actual range-capable values (slices, arrays, maps, channels, strings) and other compile-time issues. This applies to all Go files across the repository.

Applied to files:

  • plugins/governance/main.go
  • core/schemas/plugin.go
📚 Learning: 2025-12-22T10:50:40.990Z
Learnt from: Pratham-Mishra04
Repo: maximhq/bifrost PR: 1154
File: plugins/governance/store.go:1165-1186
Timestamp: 2025-12-22T10:50:40.990Z
Learning: In the Bifrost governance plugin, budgets and rate limits have 1:1 relationships with their parent entities (virtual keys, teams, customers). Do not assume sharing; ensure cascade deletion logic only deletes budgets/rate limits when there are no shared references. Enforce invariants in code and add tests to verify no cross-entity sharing and that cascade deletes only remove the specific child of the parent. If a counterexample arises, adjust data model or add guards.

Applied to files:

  • plugins/governance/main.go
🧬 Code graph analysis (1)
plugins/governance/main.go (2)
core/schemas/utils.go (1)
  • Ptr (14-16)
core/utils.go (1)
  • Ptr (56-58)
🔇 Additional comments (6)
core/changelog.md (1)

1-1: LGTM!

The changelog entry clearly describes the feature addition.

plugins/governance/main.go (1)

232-260: LGTM!

The refactoring to use CaseInsensitiveHeaderLookup() from the core schemas is clean and consistent. The logic flow for extracting virtual keys from various headers remains unchanged while benefiting from the centralized case-insensitive lookup implementation.

docs/plugins/writing-wasm-plugin.mdx (1)

754-758: LGTM!

The documentation correctly explains the case-insensitive handling requirements for WASM plugins and appropriately references the Go native helper methods as a pattern to follow.

core/schemas/plugin.go (1)

39-67: LGTM!

The implementation is well-structured with appropriate defensive checks. The lookup order (exact match → lowercase → case-insensitive iteration) is optimal for performance, prioritizing common cases first.

docs/plugins/writing-go-plugin.mdx (2)

94-104: LGTM!

The example code clearly demonstrates the recommended pattern for reading headers using the case-insensitive helper method.


232-249: LGTM!

The Note block provides clear guidance with good examples showing the flexibility of the helper methods across different casing conventions.

Comment thread core/schemas/plugin.go Outdated
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 01-09-chore_added_case-insensitive_helper_methods_for_header_and_query_parameter_lookups_in_httprequest branch from a96208e to 1b5ab71 Compare January 12, 2026 08:00
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @docs/plugins/writing-wasm-plugin.mdx:
- Around line 754-758: The comments on the HTTPRequest struct incorrectly state
that header/query keys are lowercase; update the comment above the HTTPRequest
type (remove the phrase "keys are lowercase") to reflect that headers and query
parameters preserve the original casing sent by the client and recommend using
CaseInsensitiveHeaderLookup() and CaseInsensitiveQueryLookup() helpers for
lookup; keep the rest of the comment intact and ensure it matches behavior
verified by fasthttpToHTTPRequest and TestFasthttpToHTTPRequest.
🧹 Nitpick comments (1)
core/changelog.md (1)

1-1: Consider using "feat:" prefix for consistency.

The PR title uses "feat:" but this changelog entry uses "chore:". Since this introduces new public API methods (CaseInsensitiveHeaderLookup and CaseInsensitiveQueryLookup), "feat:" would be more appropriate to accurately categorize the change.

Suggested fix
-- chore: added case-insensitive helper methods for header and query parameter lookups in HTTPRequest
+- feat: added case-insensitive helper methods for header and query parameter lookups in HTTPRequest
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a96208e and 1b5ab71.

📒 Files selected for processing (5)
  • core/changelog.md
  • core/schemas/plugin.go
  • docs/plugins/writing-go-plugin.mdx
  • docs/plugins/writing-wasm-plugin.mdx
  • plugins/governance/main.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • plugins/governance/main.go
  • docs/plugins/writing-go-plugin.mdx
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

always check the stack if there is one for the current PR. do not give localized reviews for the PR, always see all changes in the light of the whole stack of PRs (if there is a stack, if there is no stack you can continue to make localized suggestions/reviews)

Files:

  • docs/plugins/writing-wasm-plugin.mdx
  • core/schemas/plugin.go
  • core/changelog.md
🧠 Learnings (3)
📚 Learning: 2025-12-30T05:37:48.365Z
Learnt from: Pratham-Mishra04
Repo: maximhq/bifrost PR: 1180
File: docs/features/mcp/connecting-to-servers.mdx:452-458
Timestamp: 2025-12-30T05:37:48.365Z
Learning: When reviewing documentation PRs in a Graphite-managed stack, first check related or previous PRs in the stack for feature implementations before flagging documentation as incorrect or unsupported. Documentation MDX files often reference features implemented in earlier stack PRs; verify that the documented behavior exists in earlier changes and that the docs accurately reflect the implemented state before requesting edits.

Applied to files:

  • docs/plugins/writing-wasm-plugin.mdx
📚 Learning: 2025-12-09T17:07:42.007Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1006
File: core/schemas/account.go:9-18
Timestamp: 2025-12-09T17:07:42.007Z
Learning: In core/schemas/account.go, the HuggingFaceKeyConfig field within the Key struct is currently unused and reserved for future Hugging Face inference endpoint deployments. Do not flag this field as missing from OpenAPI documentation or require its presence in the API spec until the feature is actively implemented and used. When the feature is added, update the OpenAPI docs accordingly; otherwise, treat this field as non-breaking and not part of the current API surface.

Applied to files:

  • core/schemas/plugin.go
📚 Learning: 2025-12-29T11:54:55.836Z
Learnt from: akshaydeo
Repo: maximhq/bifrost PR: 1153
File: framework/configstore/rdb.go:2221-2246
Timestamp: 2025-12-29T11:54:55.836Z
Learning: In Go reviews, do not flag range-over-int patterns like for i := range n as compile-time errors, assuming Go 1.22+ semantics. Only flag actual range-capable values (slices, arrays, maps, channels, strings) and other compile-time issues. This applies to all Go files across the repository.

Applied to files:

  • core/schemas/plugin.go
🔇 Additional comments (2)
core/schemas/plugin.go (2)

39-47: LGTM!

The public API methods are clean and provide a straightforward interface for case-insensitive lookups. The delegation to a shared helper promotes code reuse.


49-71: Well-designed lookup with progressive fallback strategy.

The three-tier approach (exact → lowercase → case-insensitive iteration) is a good optimization that provides O(1) performance for the common cases while maintaining full case-insensitivity via the fallback iteration. The nil/empty guards are appropriate.

Comment thread docs/plugins/writing-wasm-plugin.mdx
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 01-09-chore_added_case-insensitive_helper_methods_for_header_and_query_parameter_lookups_in_httprequest branch from 1b5ab71 to fc800e9 Compare January 12, 2026 08:21
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
core/schemas/plugin.go (1)

49-71: Well-structured three-tier lookup strategy.

The implementation is efficient with good defensive checks:

  1. O(1) exact match first
  2. O(1) lowercase optimization for headers commonly stored in lowercase
  3. O(n) fallback for complete case-insensitivity

Consider expanding the comment on line 59 to clarify the optimization rationale:

📝 Optional: clarify comment
-	// lower key checks
+	// Optimization: check lowercase key directly (common for HTTP headers stored normalized)
 	lowerKey := strings.ToLower(key)
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5ab71 and fc800e9.

📒 Files selected for processing (5)
  • core/changelog.md
  • core/schemas/plugin.go
  • docs/plugins/writing-go-plugin.mdx
  • docs/plugins/writing-wasm-plugin.mdx
  • plugins/governance/main.go
✅ Files skipped from review due to trivial changes (1)
  • core/changelog.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • docs/plugins/writing-wasm-plugin.mdx
  • docs/plugins/writing-go-plugin.mdx
  • plugins/governance/main.go
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

always check the stack if there is one for the current PR. do not give localized reviews for the PR, always see all changes in the light of the whole stack of PRs (if there is a stack, if there is no stack you can continue to make localized suggestions/reviews)

Files:

  • core/schemas/plugin.go
🧠 Learnings (2)
📚 Learning: 2025-12-09T17:07:42.007Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1006
File: core/schemas/account.go:9-18
Timestamp: 2025-12-09T17:07:42.007Z
Learning: In core/schemas/account.go, the HuggingFaceKeyConfig field within the Key struct is currently unused and reserved for future Hugging Face inference endpoint deployments. Do not flag this field as missing from OpenAPI documentation or require its presence in the API spec until the feature is actively implemented and used. When the feature is added, update the OpenAPI docs accordingly; otherwise, treat this field as non-breaking and not part of the current API surface.

Applied to files:

  • core/schemas/plugin.go
📚 Learning: 2025-12-29T11:54:55.836Z
Learnt from: akshaydeo
Repo: maximhq/bifrost PR: 1153
File: framework/configstore/rdb.go:2221-2246
Timestamp: 2025-12-29T11:54:55.836Z
Learning: In Go reviews, do not flag range-over-int patterns like for i := range n as compile-time errors, assuming Go 1.22+ semantics. Only flag actual range-capable values (slices, arrays, maps, channels, strings) and other compile-time issues. This applies to all Go files across the repository.

Applied to files:

  • core/schemas/plugin.go
🔇 Additional comments (1)
core/schemas/plugin.go (1)

39-47: Clean delegation pattern for the public API.

The methods are minimal and correctly delegate to the shared helper. The documentation clearly describes the case-insensitive behavior.

@Pratham-Mishra04 Pratham-Mishra04 merged commit 613dfe3 into v1.4.0 Jan 12, 2026
5 checks passed
@Pratham-Mishra04 Pratham-Mishra04 deleted the 01-09-chore_added_case-insensitive_helper_methods_for_header_and_query_parameter_lookups_in_httprequest branch January 12, 2026 08:57
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