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

unify service builders

This commit is contained in:
Nikolay Kim
2019-03-09 10:39:06 -08:00
parent ca73f178c9
commit d026821924
11 changed files with 300 additions and 619 deletions

View File

@ -1,9 +1,8 @@
use std::{env, io};
use actix_http::HttpMessage;
use actix_http::{h1, Request, Response};
use actix_http::{HttpService, Request, Response};
use actix_server::Server;
use actix_service::NewService;
use bytes::Bytes;
use futures::Future;
use http::header::HeaderValue;
@ -15,10 +14,9 @@ fn main() -> io::Result<()> {
Server::build()
.bind("echo", "127.0.0.1:8080", || {
h1::H1Service::build()
HttpService::build()
.client_timeout(1000)
.client_disconnect(1000)
.server_hostname("localhost")
.finish(|mut req: Request| {
req.body().limit(512).and_then(|bytes: Bytes| {
info!("request body: {:?}", bytes);
@ -27,7 +25,6 @@ fn main() -> io::Result<()> {
Ok(res.body(bytes))
})
})
.map(|_| ())
})?
.run()
}

View File

@ -2,9 +2,8 @@ use std::{env, io};
use actix_http::http::HeaderValue;
use actix_http::HttpMessage;
use actix_http::{h1, Error, Request, Response};
use actix_http::{Error, HttpService, Request, Response};
use actix_server::Server;
use actix_service::NewService;
use bytes::Bytes;
use futures::Future;
use log::info;
@ -24,12 +23,7 @@ fn main() -> io::Result<()> {
Server::build()
.bind("echo", "127.0.0.1:8080", || {
h1::H1Service::build()
.client_timeout(1000)
.client_disconnect(1000)
.server_hostname("localhost")
.finish(|_req: Request| handle_request(_req))
.map(|_| ())
HttpService::build().finish(|_req: Request| handle_request(_req))
})?
.run()
}

View File

@ -1,8 +1,7 @@
use std::{env, io};
use actix_http::{h1, Response};
use actix_http::{HttpService, Response};
use actix_server::Server;
use actix_service::NewService;
use futures::future;
use http::header::HeaderValue;
use log::info;
@ -13,17 +12,15 @@ fn main() -> io::Result<()> {
Server::build()
.bind("hello-world", "127.0.0.1:8080", || {
h1::H1Service::build()
HttpService::build()
.client_timeout(1000)
.client_disconnect(1000)
.server_hostname("localhost")
.finish(|_req| {
info!("{:?}", _req);
let mut res = Response::Ok();
res.header("x-head", HeaderValue::from_static("dummy value!"));
future::ok::<_, ()>(res.body("Hello world!"))
})
.map(|_| ())
})?
.run()
}