Add headers argument to redirect() calls. (#287)

* Add headers argument to redirect() calls.

* Fix mistype.
This commit is contained in:
Eugene Kabanov 2022-06-17 12:17:49 +03:00 committed by GitHub
parent 61fbbc5512
commit 2a5095505f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 4 deletions

View File

@ -1322,17 +1322,35 @@ proc respond*(req: HttpRequestRef, code: HttpCode): Future[HttpResponseRef] =
## Responds to the request with specified ``HttpCode`` only.
respond(req, code, "", HttpTable.init())
proc redirect*(req: HttpRequestRef, code: HttpCode,
location: string, headers: HttpTable): Future[HttpResponseRef] =
## Responds to the request with redirection to location ``location`` and
## additional headers ``headers``.
##
## Note, ``location`` argument's value has priority over "Location" header's
## value in ``headers`` argument.
var mheaders = headers
mheaders.set("location", location)
respond(req, code, "", mheaders)
proc redirect*(req: HttpRequestRef, code: HttpCode,
location: Uri, headers: HttpTable): Future[HttpResponseRef] =
## Responds to the request with redirection to location ``location`` and
## additional headers ``headers``.
##
## Note, ``location`` argument's value has priority over "Location" header's
## value in ``headers`` argument.
redirect(req, code, $location, headers)
proc redirect*(req: HttpRequestRef, code: HttpCode,
location: Uri): Future[HttpResponseRef] =
## Responds to the request with redirection to location ``location``.
let headers = HttpTable.init([("location", $location)])
respond(req, code, "", headers)
redirect(req, code, location, HttpTable.init())
proc redirect*(req: HttpRequestRef, code: HttpCode,
location: string): Future[HttpResponseRef] =
## Responds to the request with redirection to location ``location``.
let headers = HttpTable.init([("location", location)])
respond(req, code, "", headers)
redirect(req, code, location, HttpTable.init())
proc responded*(req: HttpRequestRef): bool =
## Returns ``true`` if request ``req`` has been responded or responding.