mirror of
https://github.com/notrab/dumbo.git
synced 2025-01-16 21:58:25 +01:00
feat: handle redirects
This commit is contained in:
parent
f96cfaf1db
commit
d401b1dbb0
@ -86,6 +86,12 @@ $app->use(function ($c, $next) {
|
||||
return $next($c);
|
||||
});
|
||||
|
||||
$app->get("/redirect", function ($c) {
|
||||
$message = $c->get("message");
|
||||
|
||||
return $c->redirect("/greet/hello?name=jamie", 301);
|
||||
});
|
||||
|
||||
$app->get("/", function ($c) {
|
||||
$message = $c->get("message");
|
||||
|
||||
|
@ -64,4 +64,9 @@ class Context
|
||||
{
|
||||
return isset($this->variables[$key]);
|
||||
}
|
||||
|
||||
public function redirect($url, $status = 302)
|
||||
{
|
||||
return $this->res->redirect($url, $status);
|
||||
}
|
||||
}
|
||||
|
@ -90,13 +90,13 @@ class Dumbo
|
||||
$this->server->sendResponse(
|
||||
$response->getStatusCode(),
|
||||
$response->getHeaders(),
|
||||
$response->getBody()
|
||||
$response->getBody() ?? ""
|
||||
);
|
||||
} elseif ($response !== null) {
|
||||
$this->server->sendResponse(
|
||||
200,
|
||||
["Content-Type" => "text/plain"],
|
||||
$response
|
||||
(string) $response
|
||||
);
|
||||
} else {
|
||||
$this->server->sendResponse(204, [], "");
|
||||
|
@ -60,4 +60,12 @@ class Response
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
public function redirect($url, $status = 302)
|
||||
{
|
||||
$this->statusCode = $status;
|
||||
$this->header("Location", $url);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user