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:
Bartek Ciszkowski 2020-05-15 03:42:12 -04:00 committed by GitHub
parent f12e237da5
commit 41ad780073
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -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=":/%#?&=@[]!$&'()*+,;")