diff --git a/chronos/apps/http/httpserver.nim b/chronos/apps/http/httpserver.nim index e09b532..104c9be 100644 --- a/chronos/apps/http/httpserver.nim +++ b/chronos/apps/http/httpserver.nim @@ -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.