Repository: litestar-org/litestar

Issue:
Enhancement: make 302 the default status_code for Redirect
### Summary

I wish `Redirect()` would have a default status_code of 302. This is, I believe, the most common use case.

### Basic Example

```
Redirect(url)
```
instead of
```
Redirect(url, status_code=HTTP_302_FOUND)
```

### Drawbacks and Impact

No impact on existing code.

Some people may use 302 by default when they actually meant to use something else.

### Unresolved questions

_No response_

<!-- POLAR PLEDGE BADGE START -->
---

## Funding
* If you would like to see an issue prioritized, make a pledge towards it!
* We receive the pledge once the issue is completed & verified

<a href="https://polar.sh/litestar-org/litestar/issues/2138">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/2138/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/2138/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->

Enhancement: make 302 the default status_code for Redirect
### Summary

I wish `Redirect()` would have a default status_code of 302. This is, I believe, the most common use case.

### Basic Example

```
Redirect(url)
```
instead of
```
Redirect(url, status_code=HTTP_302_FOUND)
```

### Drawbacks and Impact

No impact on existing code.

Some people may use 302 by default when they actually meant to use something else.

### Unresolved questions

_No response_

<!-- POLAR PLEDGE BADGE START -->
---

## Funding
* If you would like to see an issue prioritized, make a pledge towards it!
* We receive the pledge once the issue is completed & verified

<a href="https://polar.sh/litestar-org/litestar/issues/2138">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/2138/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/2138/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->



Discussion:

Resolving patch:
diff --git a/litestar/response/redirect.py b/litestar/response/redirect.py
--- a/litestar/response/redirect.py
+++ b/litestar/response/redirect.py
@@ -6,7 +6,7 @@
 from litestar.enums import MediaType
 from litestar.exceptions import ImproperlyConfiguredException
 from litestar.response.base import ASGIResponse, Response
-from litestar.status_codes import HTTP_307_TEMPORARY_REDIRECT
+from litestar.status_codes import HTTP_302_FOUND
 from litestar.utils import url_quote
 from litestar.utils.helpers import filter_cookies, get_enum_string_value
 
@@ -40,7 +40,7 @@ def __init__(
     ) -> None:
         headers = {**(headers or {}), "location": url_quote(path)}
         media_type = media_type or MediaType.TEXT
-        status_code = status_code or HTTP_307_TEMPORARY_REDIRECT
+        status_code = status_code or HTTP_302_FOUND
 
         if status_code not in REDIRECT_STATUS_CODES:
             raise ImproperlyConfiguredException(
@@ -95,6 +95,8 @@ def __init__(
                 supported.
         """
         self.url = path
+        if status_code is None:
+            status_code = HTTP_302_FOUND
         super().__init__(
             background=background,
             content=b"",


Test patch:
diff --git a/tests/unit/test_openapi/test_responses.py b/tests/unit/test_openapi/test_responses.py
--- a/tests/unit/test_openapi/test_responses.py
+++ b/tests/unit/test_openapi/test_responses.py
@@ -249,6 +249,23 @@ def handler() -> Stream:
 
 
 def test_create_success_response_redirect() -> None:
+    @get(path="/test", name="test")
+    def redirect_handler() -> Redirect:
+        return Redirect(path="/target")
+
+    handler = get_registered_route_handler(redirect_handler, "test")
+
+    response = create_success_response(handler, SchemaCreator(generate_examples=True))
+    assert response.description == "Redirect Response"
+    assert response.headers
+    location = response.headers["location"]
+    assert isinstance(location, OpenAPIHeader)
+    assert isinstance(location.schema, Schema)
+    assert location.schema.type == OpenAPIType.STRING
+    assert location.description
+
+
+def test_create_success_response_redirect_override() -> None:
     @get(path="/test", status_code=HTTP_307_TEMPORARY_REDIRECT, name="test")
     def redirect_handler() -> Redirect:
         return Redirect(path="/target")
diff --git a/tests/unit/test_response/test_redirect_response.py b/tests/unit/test_response/test_redirect_response.py
--- a/tests/unit/test_response/test_redirect_response.py
+++ b/tests/unit/test_response/test_redirect_response.py
@@ -110,8 +110,8 @@ def handler() -> Redirect:
 def test_redirect(handler_status_code: Optional[int]) -> None:
     @get("/", status_code=handler_status_code)
     def handler() -> Redirect:
-        return Redirect(path="/something-else", status_code=301)
+        return Redirect(path="/something-else", status_code=handler_status_code)  # type: ignore[arg-type]
 
     with create_test_client([handler]) as client:
         res = client.get("/", follow_redirects=False)
-        assert res.status_code == 301
+        assert res.status_code == 302 if handler_status_code is None else handler_status_code