mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
simplify middleware api; fix examples
This commit is contained in:
@ -15,11 +15,10 @@ impl Actor for MyRoute {
|
||||
impl Route for MyRoute {
|
||||
type State = ();
|
||||
|
||||
fn request(req: &mut HttpRequest, payload: Payload,
|
||||
ctx: &mut HttpContext<Self>) -> RouteResult<Self> {
|
||||
fn request(mut req: HttpRequest, ctx: &mut HttpContext<Self>) -> RouteResult<Self> {
|
||||
println!("{:?}", req);
|
||||
|
||||
let multipart = req.multipart(payload)?;
|
||||
let multipart = req.multipart()?;
|
||||
|
||||
// get Multipart stream
|
||||
WrapStream::<MyRoute>::actstream(multipart)
|
||||
|
@ -9,7 +9,7 @@ use std::io::Read;
|
||||
use actix_web::*;
|
||||
|
||||
/// somple handle
|
||||
fn index(req: &mut HttpRequest, _payload: Payload, state: &()) -> HttpResponse {
|
||||
fn index(req: HttpRequest) -> HttpResponse {
|
||||
println!("{:?}", req);
|
||||
httpcodes::HTTPOk
|
||||
.builder()
|
||||
@ -36,7 +36,7 @@ fn main() {
|
||||
// register simple handler, handle all methods
|
||||
.handler("/index.html", index)
|
||||
// with path parameters
|
||||
.resource("/", |r| r.handler(Method::GET, |req, _, _| {
|
||||
.resource("/", |r| r.handler(Method::GET, |req| {
|
||||
Ok(httpcodes::HTTPFound
|
||||
.builder()
|
||||
.header("LOCATION", "/index.html")
|
||||
|
@ -48,13 +48,13 @@ impl Actor for WsChatSession {
|
||||
impl Route for WsChatSession {
|
||||
type State = WsChatSessionState;
|
||||
|
||||
fn request(req: &mut HttpRequest,
|
||||
payload: Payload, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
|
||||
fn request(mut req: HttpRequest<WsChatSessionState>,
|
||||
ctx: &mut HttpContext<Self>) -> RouteResult<Self>
|
||||
{
|
||||
// websocket handshakre, it may fail if request is not websocket request
|
||||
let resp = ws::handshake(&req)?;
|
||||
ctx.start(resp);
|
||||
ctx.add_stream(ws::WsStream::new(payload));
|
||||
ctx.add_stream(ws::WsStream::new(&mut req));
|
||||
Reply::async(
|
||||
WsChatSession {
|
||||
id: 0,
|
||||
@ -207,10 +207,10 @@ fn main() {
|
||||
|
||||
// Create Http server with websocket support
|
||||
HttpServer::new(
|
||||
Application::builder("/", state)
|
||||
Application::build("/", state)
|
||||
// redirect to websocket.html
|
||||
.resource("/", |r|
|
||||
r.handler(Method::GET, |req, payload, state| {
|
||||
r.handler(Method::GET, |req| {
|
||||
Ok(httpcodes::HTTPFound
|
||||
.builder()
|
||||
.header("LOCATION", "/static/websocket.html")
|
||||
|
Reference in New Issue
Block a user