Skip to content

rpcserver: add header extraction and transformation helpers#67

Closed
odysseus0 wants to merge 3 commits intomainfrom
feature/header-helpers
Closed

rpcserver: add header extraction and transformation helpers#67
odysseus0 wants to merge 3 commits intomainfrom
feature/header-helpers

Conversation

@odysseus0
Copy link
Contributor

@odysseus0 odysseus0 commented Jan 25, 2026

Summary

Add utilities for extracting HTTP headers in the JSON-RPC request chain. Headers are passed through as-is (no transformation).

New: headers.go

  • ExtractHeaders(req, names) - extract specified headers from request
  • Header constants: HeaderUserAgent, HeaderOrigin, HeaderFlashbotsOrigin, HeaderFlashbotsSignature
  • Default list: EdgeHeaders (User-Agent, Origin)

Modified: jsonrpc_server.go

  • Added Header(ctx, name) - nil-safe helper to get header value from request in context

Usage

// Extract headers at edge
headers := rpcserver.ExtractHeaders(req, rpcserver.EdgeHeaders)

// Read from context in downstream service
userAgent := rpcserver.Header(ctx, rpcserver.HeaderUserAgent)
origin := rpcserver.Header(ctx, rpcserver.HeaderOrigin)

Test plan

  • Unit tests for ExtractHeaders
  • Tests for nil request handling
  • Tests for header constants

🤖 Generated with Claude Code

Add utilities for extracting and transforming HTTP headers in the
JSON-RPC request chain:

- headers.go: ExtractHeaders, TransformToFlashbots, header constants
- Header(ctx, name): nil-safe helper to get header from request context

Used by protect-rpc (edge transformation), protect-of-api (passthrough),
and mev-share-node (storage) for User-Agent and Origin header logging.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@odysseus0 odysseus0 force-pushed the feature/header-helpers branch from 8fecfd6 to ac89d8a Compare January 25, 2026 23:51
Add ExtractHeaders() to extract specified headers from HTTP requests.
Keep headers as-is (no transformation to X-Flashbots-* format).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@odysseus0 odysseus0 force-pushed the feature/header-helpers branch from ac89d8a to 2899961 Compare January 27, 2026 18:11
Removes Header(ctx, name) wrapper and headers.go utilities.
Keep GetRequest(ctx) - callers can use GetRequest(ctx).Header.Get() directly.

Reverts 2c64ffd and 2899961.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@odysseus0 odysseus0 closed this Jan 28, 2026
@odysseus0 odysseus0 deleted the feature/header-helpers branch January 28, 2026 23:47
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.

1 participant