mirror of
https://github.com/SinTan1729/chhoto-url
synced 2024-12-26 23:58:35 -06:00
Use 404 response code when appropriate
This commit is contained in:
parent
ff4801a476
commit
ca01676916
1 changed files with 4 additions and 2 deletions
|
@ -2,7 +2,9 @@ use actix_files::{Files, NamedFile};
|
||||||
use actix_session::{storage::CookieSessionStore, Session, SessionMiddleware};
|
use actix_session::{storage::CookieSessionStore, Session, SessionMiddleware};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
cookie::Key,
|
cookie::Key,
|
||||||
delete, get, middleware, post,
|
delete, get,
|
||||||
|
http::StatusCode,
|
||||||
|
middleware, post,
|
||||||
web::{self, Redirect},
|
web::{self, Redirect},
|
||||||
App, HttpResponse, HttpServer, Responder,
|
App, HttpResponse, HttpServer, Responder,
|
||||||
};
|
};
|
||||||
|
@ -67,7 +69,7 @@ async fn link_handler(shortlink: web::Path<String>, data: web::Data<AppState>) -
|
||||||
let shortlink_str = shortlink.to_string();
|
let shortlink_str = shortlink.to_string();
|
||||||
let longlink = utils::get_longurl(shortlink_str, &data.db);
|
let longlink = utils::get_longurl(shortlink_str, &data.db);
|
||||||
if longlink == *"" {
|
if longlink == *"" {
|
||||||
Redirect::to("/err/404")
|
Redirect::to("/err/404").using_status_code(StatusCode::NOT_FOUND)
|
||||||
} else {
|
} else {
|
||||||
database::add_hit(shortlink.as_str(), &data.db);
|
database::add_hit(shortlink.as_str(), &data.db);
|
||||||
Redirect::to(longlink).permanent()
|
Redirect::to(longlink).permanent()
|
||||||
|
|
Loading…
Reference in a new issue