fix: map interactive UI query params to request headers for GET-based toggles#1225
Open
VarunKumar-05 wants to merge 2 commits intojina-ai:mainfrom
Open
fix: map interactive UI query params to request headers for GET-based toggles#1225VarunKumar-05 wants to merge 2 commits intojina-ai:mainfrom
VarunKumar-05 wants to merge 2 commits intojina-ai:mainfrom
Conversation
…ased UI toggles - Add __mapQueryToHeaders middleware to translate query params to headers - Support friendly param names: respond_with, with_generated_alt, no_cache, etc. - Add debug logging to crawler.ts to verify header mapping - Fixes issue jina-ai#1224: Interactive builder UI toggles now work correctly
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.
🐛 Problem Statement
The interactive code builder in the Jina Reader API has a critical bug: UI toggles don't affect the actual API request behavior because they're sent as query parameters but the server only recognizes header-based options.
Evidence from Issue #1224
User Report:
Root Cause (HAR Analysis):
The interactive builder issues simple GET requests with query parameters (e.g.,
?respond_with=markdown&with_generated_alt=true), but the server-side code only checks request headers (e.g.,x-respond-with,x-with-generated-alt). This causes all UI toggles to be silently ignored.Example GET Request from UI (non-functional):
The query params are never mapped to headers, so downstream code sees no options set.
✅ Solution
This PR implements a server-side compatibility layer that maps well-known query parameters to their corresponding request headers. This is:
Changes Made
File:
src/services/registry.tsAdded
__mapQueryToHeadersmiddleware method that translates UI-friendly query params into request headers:?respond_with=markdown→x-respond-with: markdown?with_generated_alt=true→x-with-generated-alt: true?no_cache=true→x-no-cache: true?wait_for_selector=#content→x-wait-for-selector: #content?target_selector=.main→x-target-selector: .main?proxy=https://proxy:3128→x-proxy-url: https://proxy:3128?cache_tolerance=120→x-cache-tolerance: 120?timeout=30→x-timeout: 30?accept=application/json→Accept: application/jsonrespondWith,withGeneratedAlt)Integrated middleware into
koaMiddlewaresarray (runs after CORS, before body parser)File:
src/api/crawler.ts(Debug support)crawl()handler:🧪 Testing Steps
Test 1: Query Params → Headers Mapping (via curl)
Before PR: Headers would be empty/missing
After PR: Headers populated from query params
Test 2: Verify Debug Logs
Watch server logs during any request:
Test 3: Interactive Builder Integration
?respond_with=markdownTest 4: Backward Compatibility
All existing header-based clients must continue working unchanged:
🔒 Safety & Design Rationale
Why This Approach?
Error Handling
If query param mapping fails (e.g., malformed value), the error is logged and the request continues:
Performance Impact
Negligible—mapping runs once per request, only iterates over ~10 known query param keys, uses simple string operations.
📋 Checklist
src/services/registry.tssrc/api/crawler.ts🎯 Impact
Before This PR
After This PR
🔗 Related Issues
💡 Future Recommendations (Optional)
Ideal Long-Term Fix
Update the interactive builder frontend to:
fetch()with proper request headers (clearer semantics)This ensures all clients—whether using headers or query params—have consistent behavior.
Testing Environment: