mirror of
https://github.com/actix/actix-website
synced 2025-02-08 22:36:07 +01:00
fix chunked example
This commit is contained in:
parent
b8e2a2310c
commit
4fffc16668
@ -71,16 +71,5 @@ The type `T` must implement the `Serialize` trait from *serde*.
|
|||||||
|
|
||||||
{{< include-example example="responses" file="json_resp.rs" section="json-resp" >}}
|
{{< include-example example="responses" file="json_resp.rs" section="json-resp" >}}
|
||||||
|
|
||||||
# Chunked transfer encoding
|
|
||||||
|
|
||||||
Chunked encoding on a response can be enabled with `HttpResponseBuilder::chunked()`.
|
|
||||||
This takes effect only for `Body::Streaming(BodyStream)` or `Body::StreamingContext` bodies.
|
|
||||||
If the response payload compression is enabled and a streaming body is used, chunked encoding
|
|
||||||
is enabled automatically.
|
|
||||||
|
|
||||||
> Enabling chunked encoding for *HTTP/2.0* responses is forbidden.
|
|
||||||
|
|
||||||
{{< include-example example="responses" file="chunked.rs" section="chunked" >}}
|
|
||||||
|
|
||||||
[responsebuilder]: https://docs.rs/actix-web/2/actix_web/dev/struct.HttpResponseBuilder.html
|
[responsebuilder]: https://docs.rs/actix-web/2/actix_web/dev/struct.HttpResponseBuilder.html
|
||||||
[compressmidddleware]: https://docs.rs/actix-web/2/actix_web/middleware/struct.Compress.html
|
[compressmidddleware]: https://docs.rs/actix-web/2/actix_web/middleware/struct.Compress.html
|
||||||
|
@ -8,4 +8,4 @@ actix-web = "2.0"
|
|||||||
actix-rt = "1.0"
|
actix-rt = "1.0"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
bytes = "0.4"
|
bytes = "0.5"
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
// <chunked>
|
// <chunked>
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse, Error};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::future::ok;
|
use futures::future::ok;
|
||||||
use futures::stream::once;
|
use futures::stream::once;
|
||||||
|
|
||||||
async fn index(req: HttpRequest) -> HttpResponse {
|
async fn index(req: HttpRequest) -> HttpResponse {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.chunked()
|
|
||||||
.streaming(once(ok::<_, Error>(Bytes::from_static(b"data"))))
|
.streaming(once(ok::<_, Error>(Bytes::from_static(b"data"))))
|
||||||
}
|
}
|
||||||
// </chunked>
|
// </chunked>
|
||||||
@ -17,6 +16,5 @@ pub fn main() {
|
|||||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.run()
|
.run();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user