From 32022a5ec17e9f20905bb378e922ef9a3f85e1e3 Mon Sep 17 00:00:00 2001 From: Zhengliang Wu Date: Mon, 21 Nov 2022 22:47:48 +0800 Subject: [PATCH] add content_type for basic example response body to decode utf-8 correctly (#586) --- basics/basics/src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/basics/basics/src/main.rs b/basics/basics/src/main.rs index 305d125..6f95fe8 100644 --- a/basics/basics/src/main.rs +++ b/basics/basics/src/main.rs @@ -58,11 +58,13 @@ async fn default_handler(req_method: Method) -> Result { async fn response_body(path: web::Path) -> HttpResponse { let name = path.into_inner(); - HttpResponse::Ok().streaming(stream! { - yield Ok::<_, Infallible>(web::Bytes::from("Hello ")); - yield Ok::<_, Infallible>(web::Bytes::from(name)); - yield Ok::<_, Infallible>(web::Bytes::from("!")); - }) + HttpResponse::Ok() + .content_type(ContentType::plaintext()) + .streaming(stream! { + yield Ok::<_, Infallible>(web::Bytes::from("Hello ")); + yield Ok::<_, Infallible>(web::Bytes::from(name)); + yield Ok::<_, Infallible>(web::Bytes::from("!")); + }) } /// handler with path parameters like `/user/{name}/`