fix: parse absolute-form request targets in request.URL - #1999
Conversation
href already treats GET http://host/path as a complete URL. request.URL concatenated protocol://host onto that string, producing a garbage WHATWG href.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe Merge Risk: ⚪ Minimal · up to This localized change corrects absolute-form request URL parsing while preserving existing rewrite behavior; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. 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. Comment |
Reviewer's GuideUpdates req.URL to parse HTTP/HTTPS absolute-form request targets directly, aligning it with href while retaining invalid-input handling and originalUrl semantics; adds comprehensive regression tests for schemes, hosts, ports, and path rewrites. Flow diagram for absolute-form request URL parsingflowchart TD
A["request.URL accessed"] --> B["Read originalUrl"]
B --> C{"originalUrl matches /^https?:\\/\\//i"}
C -->|yes| D["new URL(originalUrl)"]
C -->|no| E["new URL(protocol://host + originalUrl)"]
D --> F{"URL construction succeeds"}
E --> F
F -->|yes| G["Return memoizedURL"]
F -->|no| H["Return Object.create(null)"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1999 +/- ##
=======================================
Coverage 99.90% 99.90%
=======================================
Files 9 9
Lines 2125 2127 +2
=======================================
+ Hits 2123 2125 +2
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
recheck |
Problem
When the request line is HTTP/1.1 absolute-form (
GET http://example.com/foo HTTP/1.1),ctx.hrefis correct butctx.URLis not:The same garbage URL is produced even when the
Hostheader already matchesexample.com(http://example.comhttp//example.com/foo?q=1). Proxies and some health checks send this request form.Fix
hrefalready special-cases/^https?:\/\//ionoriginalUrland returns it as-is.request.URLnow uses that same branch and constructsnew URL(originalUrl)instead of concatenatingprotocol://hostonto an already-absolute URL. Invalid input still collapses toObject.create(null).URLcontinues to followoriginalUrlafterctx.path=/ctx.query=rewrites, matching the existinghreftests.Testing
Covers http / https /
HTTP:/// port / matching Host / empty Host / path rewrite. New tests fail without the change and pass with it.npm test— 447 pass, 0 fail.Summary by Sourcery
Correct
request.URLparsing for absolute-form request targets.Bug Fixes:
request.URL, preserving their original scheme, host, port, path, and query instead of generating malformed URLs.Enhancements:
request.URLaligned withhrefbehavior and preserve the existing handling of invalid URLs and rewritten paths.Tests:
Summary by CodeRabbit