1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 14:49:20 +02:00

re-introduce Body type, use Body as default body type for Response

This commit is contained in:
Nikolay Kim
2018-11-18 13:48:42 -08:00
parent 7fed50bcae
commit 8fea1367c7
16 changed files with 309 additions and 335 deletions

View File

@ -15,7 +15,7 @@ use bytes::Bytes;
use futures::future::{self, ok};
use futures::stream::once;
use actix_http::{h1, http, Body, KeepAlive, Request, Response};
use actix_http::{body, h1, http, Body, Error, KeepAlive, Request, Response};
#[test]
fn test_h1_v2() {
@ -349,11 +349,9 @@ fn test_body_length() {
.bind("test", addr, move || {
h1::H1Service::new(|_| {
let body = once(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(
Response::Ok()
.content_length(STR.len() as u64)
.body(Body::Streaming(Box::new(body))),
)
ok::<_, ()>(Response::Ok().body(Body::from_message(
body::SizedStream::new(STR.len(), body),
)))
}).map(|_| ())
}).unwrap()
.run()
@ -379,12 +377,8 @@ fn test_body_chunked_explicit() {
Server::new()
.bind("test", addr, move || {
h1::H1Service::new(|_| {
let body = once(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(
Response::Ok()
.chunked()
.body(Body::Streaming(Box::new(body))),
)
let body = once::<_, Error>(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(Response::Ok().streaming(body))
}).map(|_| ())
}).unwrap()
.run()
@ -412,8 +406,8 @@ fn test_body_chunked_implicit() {
Server::new()
.bind("test", addr, move || {
h1::H1Service::new(|_| {
let body = once(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(Response::Ok().body(Body::Streaming(Box::new(body))))
let body = once::<_, Error>(Ok(Bytes::from_static(STR.as_ref())));
ok::<_, ()>(Response::Ok().streaming(body))
}).map(|_| ())
}).unwrap()
.run()

View File

@ -18,7 +18,7 @@ use bytes::{Bytes, BytesMut};
use futures::future::{lazy, ok, Either};
use futures::{Future, IntoFuture, Sink, Stream};
use actix_http::{h1, ws, ResponseError, ServiceConfig};
use actix_http::{h1, ws, ResponseError, SendResponse, ServiceConfig};
fn ws_service(req: ws::Frame) -> impl Future<Item = ws::Message, Error = io::Error> {
match req {
@ -55,20 +55,19 @@ fn test_simple() {
match ws::verify_handshake(&req) {
Err(e) => {
// validation failed
let resp = e.error_response();
Either::A(
framed
.send(h1::Message::Item(resp))
SendResponse::send(framed, e.error_response())
.map_err(|_| ())
.map(|_| ()),
)
}
Ok(_) => Either::B(
// send response
framed
.send(h1::Message::Item(
Ok(_) => {
Either::B(
// send handshake response
SendResponse::send(
framed,
ws::handshake_response(&req).finish(),
)).map_err(|_| ())
).map_err(|_| ())
.and_then(|framed| {
// start websocket service
let framed =
@ -76,7 +75,8 @@ fn test_simple() {
ws::Transport::with(framed, ws_service)
.map_err(|_| ())
}),
),
)
}
}
} else {
panic!()