Skip to content

Commit

Permalink
refactor(example): websocket and middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3s committed Jun 27, 2023
1 parent f431128 commit 0f8b805
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/middleware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ edition = "2018"

[dependencies]
ntex = { version = "0.7.2", features = ["tokio", "cookie"] }
ntex-session = { version = "0.2.0" }
ntex-session = { version = "0.3.0" }
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
env_logger = "0.7"
env_logger = "0.10.0"
6 changes: 3 additions & 3 deletions examples/middleware/src/errorhandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use ntex::http::header;
use ntex::service::{Middleware, Service};
use ntex::util::BoxFuture;
use ntex::web;
use ntex::{web, ServiceCtx};

pub struct Error;

Expand All @@ -31,9 +31,9 @@ where

ntex::forward_poll_ready!(service);

fn call(&self, req: web::WebRequest<Err>) -> Self::Future<'_> {
fn call<'a>(&'a self, req: web::WebRequest<Err>, ctx: ServiceCtx<'a, Self>) -> Self::Future<'_> {
Box::pin(async move {
self.service.call(req).await.map(|mut res| {
ctx.call(&self.service, req).await.map(|mut res| {
let status = res.status();
if status.is_client_error() || status.is_server_error() {
res.headers_mut().insert(
Expand Down
7 changes: 3 additions & 4 deletions examples/middleware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod user_sessions;
// <simple>
use ntex::service::{Middleware, Service};
use ntex::util::BoxFuture;
use ntex::web;
use ntex::{web, ServiceCtx};

// There are two steps in middleware processing.
// 1. Middleware initialization, middleware factory gets called with
Expand Down Expand Up @@ -37,11 +37,10 @@ where

ntex::forward_poll_ready!(service);

fn call(&self, req: web::WebRequest<Err>) -> Self::Future<'_> {
fn call<'a>(&'a self, req: web::WebRequest<Err>, ctx: ServiceCtx<'a, Self>) -> Self::Future<'_> {
println!("Hi from start. You requested: {}", req.path());

let fut = self.service.call(req);

let fut = ctx.call(&self.service, req);
Box::pin(async move {
let res = fut.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/requests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ serde = "1.0"
serde_json = "1.0"
ntex = { version = "0.7.2", features = ["tokio"] }
futures = "0.3.1"
ntex-multipart = "0.2.0"
ntex-multipart = "0.3.0"
2 changes: 1 addition & 1 deletion examples/static-files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition = "2018"

[dependencies]
ntex = { version = "0.7.2", features = ["tokio"] }
ntex-files = "0.2.0"
ntex-files = "0.3.0"
mime = "0.3"

0 comments on commit 0f8b805

Please sign in to comment.