mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-27 10:39:03 +02:00
move httpmessage futures to actix-web
This commit is contained in:
@ -1,10 +1,9 @@
|
||||
use std::{env, io};
|
||||
|
||||
use actix_http::HttpMessage;
|
||||
use actix_http::{HttpService, Request, Response};
|
||||
use actix_http::{error::PayloadError, HttpService, Request, Response};
|
||||
use actix_server::Server;
|
||||
use bytes::Bytes;
|
||||
use futures::Future;
|
||||
use bytes::BytesMut;
|
||||
use futures::{Future, Stream};
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
|
||||
@ -18,12 +17,20 @@ fn main() -> io::Result<()> {
|
||||
.client_timeout(1000)
|
||||
.client_disconnect(1000)
|
||||
.finish(|mut req: Request| {
|
||||
req.body().limit(512).and_then(|bytes: Bytes| {
|
||||
info!("request body: {:?}", bytes);
|
||||
let mut res = Response::Ok();
|
||||
res.header("x-head", HeaderValue::from_static("dummy value!"));
|
||||
Ok(res.body(bytes))
|
||||
})
|
||||
req.take_payload()
|
||||
.fold(BytesMut::new(), move |mut body, chunk| {
|
||||
body.extend_from_slice(&chunk);
|
||||
Ok::<_, PayloadError>(body)
|
||||
})
|
||||
.and_then(|bytes| {
|
||||
info!("request body: {:?}", bytes);
|
||||
let mut res = Response::Ok();
|
||||
res.header(
|
||||
"x-head",
|
||||
HeaderValue::from_static("dummy value!"),
|
||||
);
|
||||
Ok(res.body(bytes))
|
||||
})
|
||||
})
|
||||
})?
|
||||
.run()
|
||||
|
@ -1,20 +1,25 @@
|
||||
use std::{env, io};
|
||||
|
||||
use actix_http::http::HeaderValue;
|
||||
use actix_http::HttpMessage;
|
||||
use actix_http::{Error, HttpService, Request, Response};
|
||||
use actix_http::{error::PayloadError, Error, HttpService, Request, Response};
|
||||
use actix_server::Server;
|
||||
use bytes::Bytes;
|
||||
use futures::Future;
|
||||
use bytes::BytesMut;
|
||||
use futures::{Future, Stream};
|
||||
use log::info;
|
||||
|
||||
fn handle_request(mut req: Request) -> impl Future<Item = Response, Error = Error> {
|
||||
req.body().limit(512).from_err().and_then(|bytes: Bytes| {
|
||||
info!("request body: {:?}", bytes);
|
||||
let mut res = Response::Ok();
|
||||
res.header("x-head", HeaderValue::from_static("dummy value!"));
|
||||
Ok(res.body(bytes))
|
||||
})
|
||||
req.take_payload()
|
||||
.fold(BytesMut::new(), move |mut body, chunk| {
|
||||
body.extend_from_slice(&chunk);
|
||||
Ok::<_, PayloadError>(body)
|
||||
})
|
||||
.from_err()
|
||||
.and_then(|bytes| {
|
||||
info!("request body: {:?}", bytes);
|
||||
let mut res = Response::Ok();
|
||||
res.header("x-head", HeaderValue::from_static("dummy value!"));
|
||||
Ok(res.body(bytes))
|
||||
})
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
|
Reference in New Issue
Block a user