fix(static): only append Vary: Accept-Encoding after a static asset match#4075
fix(static): only append Vary: Accept-Encoding after a static asset match#4075schiller-manuel wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe pull request relocates the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/unit/static-middleware.test.ts (1)
33-41: Consider adding a test for requests without Accept-Encoding.When no
Accept-Encodingheader is sent,encodings.length === 1(only the empty string), soVary: Accept-Encodingshould not be appended even when an asset is matched. This edge case would strengthen coverage of the conditional at line 49 in static.ts.💡 Suggested additional test case
it("does not append Accept-Encoding vary when asset is matched without encoding negotiation", async () => { getAsset.mockImplementation((id: string) => { if (id === "/foo.css") { return { etag: '"test"', mtime: Date.now(), type: "text/css", size: 100, }; } return undefined; }); isPublicAssetURL.mockReturnValue(true); readAsset.mockResolvedValue("body"); const event = createEvent("/foo.css"); // no accept-encoding await handler(event); expect(event.res.headers.get("Vary")).toBe("Origin"); expect(event.res.headers.get("Vary")).not.toContain("Accept-Encoding"); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/unit/static-middleware.test.ts` around lines 33 - 41, Add a unit test covering the edge case where no Accept-Encoding header is sent: mock getAsset to return a valid asset (e.g., for "/foo.css"), isPublicAssetURL to true, and readAsset to resolve the body, then create the event with createEvent("/foo.css") without an Accept-Encoding header and call handler(event); assert that event.res.headers.get("Vary") equals "Origin" and does not contain "Accept-Encoding". This ensures the conditional in static.ts that checks encodings.length prevents appending "Accept-Encoding" when only the empty encoding is present.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/unit/static-middleware.test.ts`:
- Around line 33-41: Add a unit test covering the edge case where no
Accept-Encoding header is sent: mock getAsset to return a valid asset (e.g., for
"/foo.css"), isPublicAssetURL to true, and readAsset to resolve the body, then
create the event with createEvent("/foo.css") without an Accept-Encoding header
and call handler(event); assert that event.res.headers.get("Vary") equals
"Origin" and does not contain "Accept-Encoding". This ensures the conditional in
static.ts that checks encodings.length prevents appending "Accept-Encoding" when
only the empty encoding is present.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 80108a43-6322-4f23-b15d-e4fd0983df3d
📒 Files selected for processing (2)
src/runtime/internal/static.tstest/unit/static-middleware.test.ts
No description provided.