1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

add content_type for basic example response body to decode utf-8 correctly (#586)

This commit is contained in:
Zhengliang Wu 2022-11-21 22:47:48 +08:00 committed by GitHub
parent 6fe45afe69
commit 32022a5ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,11 +58,13 @@ async fn default_handler(req_method: Method) -> Result<impl Responder> {
async fn response_body(path: web::Path<String>) -> 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}/`