feat: add RedirectResponse for convenient HTTP redirects#1367
feat: add RedirectResponse for convenient HTTP redirects#1367
Conversation
Adds a `RedirectResponse` class that sets the `Location` header and status code automatically. Defaults to 307 (Temporary Redirect). Supports 301, 302, 303, 307, and 308 redirect codes. Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
unit_tests/test_redirect_response.py (1)
4-22: Add one negative test for unsupported status codes.Current tests validate happy paths well; adding a failure-path case (e.g.,
status_code=200) will lock in redirect-only behavior and prevent regressions.✅ Suggested test addition
from robyn.responses import RedirectResponse +import pytest @@ def test_redirect_response_with_extra_headers(): @@ assert resp.headers.get("X-Custom") == "value" + + +def test_redirect_response_invalid_status_code(): + with pytest.raises(ValueError): + RedirectResponse("/target", status_code=200)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@unit_tests/test_redirect_response.py` around lines 4 - 22, Add a negative unit test in test_redirect_response.py that constructs RedirectResponse with a non-redirect status_code (e.g., status_code=200) and asserts that this is rejected or normalized to a redirect status (depending on implementation) — reference the RedirectResponse constructor and its status_code handling to locate the logic to test; ensure the test asserts the expected failure/exception or that status_code is one of allowed redirect codes (e.g., raises ValueError or sets to 307) so regressions that allow non-redirect codes are caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@robyn/responses.py`:
- Around line 32-44: The RedirectResponse.__init__ currently accepts any integer
status_code and forwards it, allowing non-redirect codes with a Location header;
update RedirectResponse.__init__ to validate the status_code is a valid redirect
code (e.g., 300–399 or explicitly one of 301,302,303,307,308) and raise a
ValueError (or TypeError) if not, before setting the Location header and calling
super().__init__; reference the RedirectResponse.__init__ constructor and the
redirect_headers/Headers usage when making the change.
---
Nitpick comments:
In `@unit_tests/test_redirect_response.py`:
- Around line 4-22: Add a negative unit test in test_redirect_response.py that
constructs RedirectResponse with a non-redirect status_code (e.g.,
status_code=200) and asserts that this is rejected or normalized to a redirect
status (depending on implementation) — reference the RedirectResponse
constructor and its status_code handling to locate the logic to test; ensure the
test asserts the expected failure/exception or that status_code is one of
allowed redirect codes (e.g., raises ValueError or sets to 307) so regressions
that allow non-redirect codes are caught.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d6735529-d16b-4bb1-b474-c6484a0fe645
📒 Files selected for processing (3)
robyn/__init__.pyrobyn/responses.pyunit_tests/test_redirect_response.py
Made-with: Cursor
for more information, see https://pre-commit.ci
Summary
RedirectResponseclass torobyn/responses.pythat extendsResponseand automatically sets theLocationheader and redirect status code.307 Temporary Redirect; also supports301,302,303, and308.RedirectResponsefrom the top-levelrobynpackage via__init__.pyand__all__.Test plan
unit_tests/test_redirect_response.pytest_redirect_response_defaults— verifies default 307 status and Location headertest_redirect_response_301— verifies permanent redirect with custom status codetest_redirect_response_with_extra_headers— verifies Location is set alongside custom headerspytest unit_tests/test_redirect_response.pyto confirm all tests passMade with Cursor
Summary by CodeRabbit
New Features
Tests