mirror of https://github.com/encode/starlette.git
RedirectResponse now accepts optional background parameter (#945)
* RedirectResponse now accepts optional background parameter With this change, a `background` task can now be sent during a RedirectResponse. This can be useful when an application wishes to run a background task after a form submission, which usually includes a redirect (e.g. to prevent resubmission) Closes #941 * Revert testing background in redirect test
This commit is contained in:
parent
f12e237da5
commit
41ad780073
|
@ -173,9 +173,15 @@ class UJSONResponse(JSONResponse):
|
|||
|
||||
class RedirectResponse(Response):
|
||||
def __init__(
|
||||
self, url: typing.Union[str, URL], status_code: int = 307, headers: dict = None
|
||||
self,
|
||||
url: typing.Union[str, URL],
|
||||
status_code: int = 307,
|
||||
headers: dict = None,
|
||||
background: BackgroundTask = None,
|
||||
) -> None:
|
||||
super().__init__(content=b"", status_code=status_code, headers=headers)
|
||||
super().__init__(
|
||||
content=b"", status_code=status_code, headers=headers, background=background
|
||||
)
|
||||
self.headers["location"] = quote_plus(str(url), safe=":/%#?&=@[]!$&'()*+,;")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue