Skip to content

Commit 40a59b7

Browse files
authored
Merge pull request #244 from helloworlde/master
Specify charset for non english words
2 parents 140f1f9 + ae4826f commit 40a59b7

File tree

11 files changed

+46
-46
lines changed

11 files changed

+46
-46
lines changed

src/endpoints/admin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub async fn post_admin(
9191
update = None;
9292
}
9393

94-
Ok(HttpResponse::Ok().content_type("text/html").body(
94+
Ok(HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
9595
AdminTemplate {
9696
pastas: &pastas,
9797
args: &ARGS,

src/endpoints/auth_admin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct AuthAdmin<'a> {
1111

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

28-
return HttpResponse::Ok().content_type("text/html").body(
28+
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
2929
AuthAdmin {
3030
args: &ARGS,
3131
status,

src/endpoints/auth_upload.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub async fn auth_upload(data: web::Data<AppState>, id: web::Path<String>) -> Ht
3333

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

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

@@ -73,7 +73,7 @@ pub async fn auth_upload_with_status(
7373

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

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

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

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

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

@@ -148,7 +148,7 @@ pub async fn auth_raw_pasta_with_status(
148148

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

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

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

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

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

@@ -223,7 +223,7 @@ pub async fn auth_edit_private_with_status(
223223

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

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

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

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

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

@@ -298,7 +298,7 @@ pub async fn auth_file_with_status(
298298

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

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

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

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

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

@@ -373,7 +373,7 @@ pub async fn auth_remove_private_with_status(
373373

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

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

src/endpoints/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct IndexTemplate<'a> {
2525

2626
#[get("/")]
2727
pub async fn index() -> impl Responder {
28-
HttpResponse::Ok().content_type("text/html").body(
28+
HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
2929
IndexTemplate {
3030
args: &ARGS,
3131
status: String::from(""),
@@ -39,7 +39,7 @@ pub async fn index() -> impl Responder {
3939
pub async fn index_with_status(param: web::Path<String>) -> HttpResponse {
4040
let status = param.into_inner();
4141

42-
return HttpResponse::Ok().content_type("text/html").body(
42+
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
4343
IndexTemplate {
4444
args: &ARGS,
4545
status,

src/endpoints/edit.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
4848
.finish();
4949
}
5050

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

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

@@ -100,7 +100,7 @@ pub async fn get_edit_with_status(
100100
.finish();
101101
}
102102

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

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

@@ -184,7 +184,7 @@ pub async fn post_edit_private(
184184
}
185185

186186
// serve pasta in template
187-
let response = HttpResponse::Ok().content_type("text/html").body(
187+
let response = HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
188188
EditTemplate {
189189
pasta: &pastas[index],
190190
args: &ARGS,
@@ -202,7 +202,7 @@ pub async fn post_edit_private(
202202
return Ok(response);
203203
}
204204
Ok(HttpResponse::Ok()
205-
.content_type("text/html")
205+
.content_type("text/html; charset=utf-8")
206206
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
207207
}
208208

@@ -296,7 +296,7 @@ pub async fn post_submit_edit_private(
296296
.finish());
297297
}
298298
Ok(HttpResponse::Ok()
299-
.content_type("text/html")
299+
.content_type("text/html; charset=utf-8")
300300
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
301301
}
302302

@@ -381,6 +381,6 @@ pub async fn post_edit(
381381
}
382382

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

src/endpoints/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ pub struct ErrorTemplate<'a> {
1111

1212
pub async fn not_found() -> Result<HttpResponse, Error> {
1313
Ok(HttpResponse::Ok()
14-
.content_type("text/html")
14+
.content_type("text/html; charset=utf-8")
1515
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
1616
}

src/endpoints/guide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ struct Guide<'a> {
1111
#[get("/guide")]
1212
pub async fn guide() -> HttpResponse {
1313
HttpResponse::Ok()
14-
.content_type("text/html")
14+
.content_type("text/html; charset=utf-8")
1515
.body(Guide { args: &ARGS }.render().unwrap())
1616
}

src/endpoints/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub async fn list(data: web::Data<AppState>) -> HttpResponse {
2828
// sort pastas in reverse-chronological order of creation time
2929
pastas.sort_by(|a, b| b.created.cmp(&a.created));
3030

31-
HttpResponse::Ok().content_type("text/html").body(
31+
HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
3232
ListTemplate {
3333
pastas: &pastas,
3434
args: &ARGS,

src/endpoints/pasta.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn pastaresponse(
8888
}
8989

9090
// serve pasta in template
91-
let response = HttpResponse::Ok().content_type("text/html").body(
91+
let response = HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
9292
PastaTemplate {
9393
pasta: &pastas[index],
9494
args: &ARGS,
@@ -121,7 +121,7 @@ fn pastaresponse(
121121

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

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

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

@@ -341,7 +341,7 @@ pub async fn getrawpasta(
341341

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

@@ -440,7 +440,7 @@ pub async fn postrawpasta(
440440

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

src/endpoints/qr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn getqr(data: web::Data<AppState>, id: web::Path<String>) -> HttpResp
5555
});
5656

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

0 commit comments

Comments
 (0)