Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify charset for non english words #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/endpoints/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub async fn post_admin(
update = None;
}

Ok(HttpResponse::Ok().content_type("text/html").body(
Ok(HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AdminTemplate {
pastas: &pastas,
args: &ARGS,
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/auth_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct AuthAdmin<'a> {

#[get("/auth_admin")]
pub async fn auth_admin() -> HttpResponse {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthAdmin {
args: &ARGS,
status: String::from(""),
Expand All @@ -25,7 +25,7 @@ pub async fn auth_admin() -> HttpResponse {
pub async fn auth_admin_with_status(param: web::Path<String>) -> HttpResponse {
let status = param.into_inner();

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthAdmin {
args: &ARGS,
status,
Expand Down
40 changes: 20 additions & 20 deletions src/endpoints/auth_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn auth_upload(data: web::Data<AppState>, id: web::Path<String>) -> Ht

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -49,7 +49,7 @@ pub async fn auth_upload(data: web::Data<AppState>, id: web::Path<String>) -> Ht
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -73,7 +73,7 @@ pub async fn auth_upload_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -89,7 +89,7 @@ pub async fn auth_upload_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -108,7 +108,7 @@ pub async fn auth_raw_pasta(data: web::Data<AppState>, id: web::Path<String>) ->

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -124,7 +124,7 @@ pub async fn auth_raw_pasta(data: web::Data<AppState>, id: web::Path<String>) ->
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -148,7 +148,7 @@ pub async fn auth_raw_pasta_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -164,7 +164,7 @@ pub async fn auth_raw_pasta_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -183,7 +183,7 @@ pub async fn auth_edit_private(data: web::Data<AppState>, id: web::Path<String>)

for (_, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -199,7 +199,7 @@ pub async fn auth_edit_private(data: web::Data<AppState>, id: web::Path<String>)
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -223,7 +223,7 @@ pub async fn auth_edit_private_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -239,7 +239,7 @@ pub async fn auth_edit_private_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -258,7 +258,7 @@ pub async fn auth_file(data: web::Data<AppState>, id: web::Path<String>) -> Http

for (_, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -274,7 +274,7 @@ pub async fn auth_file(data: web::Data<AppState>, id: web::Path<String>) -> Http
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -298,7 +298,7 @@ pub async fn auth_file_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -314,7 +314,7 @@ pub async fn auth_file_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -333,7 +333,7 @@ pub async fn auth_remove_private(data: web::Data<AppState>, id: web::Path<String

for (_, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -349,7 +349,7 @@ pub async fn auth_remove_private(data: web::Data<AppState>, id: web::Path<String
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -373,7 +373,7 @@ pub async fn auth_remove_private_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -389,6 +389,6 @@ pub async fn auth_remove_private_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}
4 changes: 2 additions & 2 deletions src/endpoints/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct IndexTemplate<'a> {

#[get("/")]
pub async fn index() -> impl Responder {
HttpResponse::Ok().content_type("text/html").body(
HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
IndexTemplate {
args: &ARGS,
status: String::from(""),
Expand All @@ -38,7 +38,7 @@ pub async fn index() -> impl Responder {
pub async fn index_with_status(param: web::Path<String>) -> HttpResponse {
let status = param.into_inner();

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
IndexTemplate {
args: &ARGS,
status,
Expand Down
16 changes: 8 additions & 8 deletions src/endpoints/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
.finish();
}

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
EditTemplate {
pasta,
args: &ARGS,
Expand All @@ -62,7 +62,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand Down Expand Up @@ -100,7 +100,7 @@ pub async fn get_edit_with_status(
.finish();
}

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
EditTemplate {
pasta,
args: &ARGS,
Expand All @@ -114,7 +114,7 @@ pub async fn get_edit_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand Down Expand Up @@ -183,7 +183,7 @@ pub async fn post_edit_private(
}

// serve pasta in template
let response = HttpResponse::Ok().content_type("text/html").body(
let response = HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
EditTemplate {
pasta: &pastas[index],
args: &ARGS,
Expand All @@ -201,7 +201,7 @@ pub async fn post_edit_private(
return Ok(response);
}
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}

Expand Down Expand Up @@ -294,7 +294,7 @@ pub async fn post_submit_edit_private(
.finish());
}
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}

Expand Down Expand Up @@ -379,6 +379,6 @@ pub async fn post_edit(
}

Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}
2 changes: 1 addition & 1 deletion src/endpoints/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pub struct ErrorTemplate<'a> {

pub async fn not_found() -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}
2 changes: 1 addition & 1 deletion src/endpoints/guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ struct Guide<'a> {
#[get("/guide")]
pub async fn guide() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(Guide { args: &ARGS }.render().unwrap())
}
2 changes: 1 addition & 1 deletion src/endpoints/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn list(data: web::Data<AppState>) -> HttpResponse {
// sort pastas in reverse-chronological order of creation time
pastas.sort_by(|a, b| b.created.cmp(&a.created));

HttpResponse::Ok().content_type("text/html").body(
HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
ListTemplate {
pastas: &pastas,
args: &ARGS,
Expand Down
14 changes: 7 additions & 7 deletions src/endpoints/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn pastaresponse(
}

// serve pasta in template
let response = HttpResponse::Ok().content_type("text/html").body(
let response = HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
PastaTemplate {
pasta: &pastas[index],
args: &ARGS,
Expand Down Expand Up @@ -117,7 +117,7 @@ fn pastaresponse(

// otherwise send pasta not found error
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand Down Expand Up @@ -226,14 +226,14 @@ fn urlresponse(data: web::Data<AppState>, id: web::Path<String>) -> HttpResponse
// send error if we're trying to open a non-url pasta as a redirect
} else {
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap());
}
}

// otherwise send pasta not found error
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand Down Expand Up @@ -313,7 +313,7 @@ pub async fn getrawpasta(

// otherwise send pasta not found error as raw text
Ok(HttpResponse::NotFound()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(String::from("Upload not found! :-(")))
}

Expand Down Expand Up @@ -408,7 +408,7 @@ pub async fn postrawpasta(

// send raw content of pasta
let response = Ok(HttpResponse::NotFound()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(pastas[index].content.to_owned()));

if pastas[index].content != original_content {
Expand All @@ -420,7 +420,7 @@ pub async fn postrawpasta(

// otherwise send pasta not found error as raw text
Ok(HttpResponse::NotFound()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(String::from("Upload not found! :-(")))
}

Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn getqr(data: web::Data<AppState>, id: web::Path<String>) -> HttpResp
};

// serve qr code in template
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
QRTemplate {
qr: &svg,
pasta: &pastas[index],
Expand All @@ -67,6 +67,6 @@ pub async fn getqr(data: web::Data<AppState>, id: web::Path<String>) -> HttpResp
// otherwise
// send pasta not found error
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}