feat: extract URL from X-Original-Path/Query headers#61
Merged
Conversation
Support header-based URL forwarding from proxyd Stage 2. If X-Original-Path header is present, reconstruct URL from headers. Otherwise fall back to r.URL (backward compatible). This enables clean separation between public API paths and internal service endpoints while maintaining consistency with other services. Context: - Public API paths like /fast are request metadata, not REST resources - Proxyd forwards these as X-Original-Path/Query headers - Internal services can serve at consistent endpoints (e.g., /api) - Backward compatible: if headers absent, uses r.URL as before
Proxyd may send X-Original-Path and X-Original-Query headers independently: - Only X-Original-Query when path is / (root) - Only X-Original-Path when there's no query string Updated logic to selectively replace path and query instead of requiring both headers to be present together. Added tests for edge cases.
Added explicit test per Tymur's requirement that simple methods should work with /fast, /whatever, and any other path - not just hardcoded paths. Tests /whatever, /anything, /custom-path, /v1/special to demonstrate the implementation is path-agnostic.
Consolidated from 6 to 4 tests with maximum value density: - Backward compatibility (no headers) - Both headers with arbitrary path (/whatever proves not hardcoded) - Edge case: only query header - Edge case: only path header Removed redundant tests while maintaining full coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Support header-based URL forwarding from proxyd Stage 2.
If
X-Original-Pathheader is present, reconstruct URL from headers. Otherwise fall back tor.URL(backward compatible).Motivation
This enables clean separation between public API paths and internal service endpoints:
/fastare request metadata, not REST resourcesX-Original-PathandX-Original-Queryheaders/api)r.URLas beforeChanges
ServeHTTPinrpcserver/jsonrpc_server.goto check forX-Original-PathheaderX-Original-PathandX-Original-Queryr.URL(existing behavior)Testing
go test ./rpcserver/... -vAll tests pass including new
TestURLExtractionwhich verifies: