mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
Final fixes before requesting review.
This commit is contained in:
@ -3,12 +3,10 @@ fn is_error() -> bool {
|
||||
}
|
||||
|
||||
// <async-stream>
|
||||
use actix_web::{error, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
use actix_web::{error, Error, HttpResponse};
|
||||
use futures::future::{result, Future};
|
||||
|
||||
fn index(
|
||||
_req: HttpRequest,
|
||||
) -> Result<Box<Future<Item = HttpResponse, Error = Error>>, Error> {
|
||||
fn index() -> Result<Box<Future<Item = HttpResponse, Error = Error>>, Error> {
|
||||
if is_error() {
|
||||
Err(error::ErrorBadRequest("bad request"))
|
||||
} else {
|
||||
@ -20,6 +18,8 @@ fn index(
|
||||
// </async-stream>
|
||||
|
||||
pub fn main() {
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::to_async(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
|
@ -1,22 +1,30 @@
|
||||
pub mod async_stream;
|
||||
pub mod stream;
|
||||
// <async-responder>
|
||||
use actix_web::{web, App, Error, HttpRequest, HttpResponse};
|
||||
use actix_web::{Error, HttpResponse};
|
||||
use futures::future::{ok, Future};
|
||||
|
||||
fn index(_req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
|
||||
fn index() -> Box<Future<Item = HttpResponse, Error = Error>> {
|
||||
Box::new(ok::<_, Error>(
|
||||
HttpResponse::Ok().content_type("text/html").body("Hello!"),
|
||||
))
|
||||
}
|
||||
|
||||
fn index2(_req: HttpRequest) -> Box<Future<Item = &'static str, Error = Error>> {
|
||||
fn index2() -> Box<Future<Item = &'static str, Error = Error>> {
|
||||
Box::new(ok::<_, Error>("Welcome!"))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.route("/async", web::to_async(index))
|
||||
.route("/", web::to_async(index2));
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.route("/async", web::to_async(index))
|
||||
.route("/", web::to_async(index2))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </async-responder>
|
||||
|
@ -1,9 +1,9 @@
|
||||
// <stream>
|
||||
use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
use actix_web::{Error, HttpResponse};
|
||||
use bytes::Bytes;
|
||||
use futures::stream::once;
|
||||
|
||||
fn index(_req: HttpRequest) -> HttpResponse {
|
||||
fn index() -> HttpResponse {
|
||||
let body = once::<Bytes, Error>(Ok(Bytes::from_static(b"test")));
|
||||
|
||||
HttpResponse::Ok()
|
||||
@ -12,6 +12,8 @@ fn index(_req: HttpRequest) -> HttpResponse {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/async", web::to_async(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
|
Reference in New Issue
Block a user