Skip to content

Commit 101e4fb

Browse files
authored
ntex: upgrade to ntex-1.0 (#8680)
1 parent 4325dbb commit 101e4fb

File tree

3 files changed

+53
-53
lines changed

3 files changed

+53
-53
lines changed

frameworks/Rust/ntex/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex"
3-
version = "0.7.0"
3+
version = "1.0.0"
44
edition = "2018"
55

66
[[bin]]
@@ -37,8 +37,8 @@ tokio = ["ntex/tokio"]
3737
async-std = ["ntex/async-std"]
3838

3939
[dependencies]
40-
ntex = "0.7.2"
41-
ntex-bytes = { version = "0.1.19", features=["simd"] }
40+
ntex = "1.0.0"
41+
ntex-bytes = { version = "0.1.21", features=["simd"] }
4242
mimalloc = { version = "0.1.25", default-features = false }
4343
snmalloc-rs = { version = "0.3.3", features = ["native-cpu"] }
4444
yarte = { version = "0.15", features = ["bytes-buf", "json"] }
@@ -52,7 +52,7 @@ serde = { version = "1.0", features = ["derive"] }
5252
serde_json = "1.0"
5353
log = { version = "0.4", features = ["release_max_level_off"] }
5454
tok_io = {version = "1", package = "tokio" }
55-
tokio-postgres = { git="https://github.com/fafhrd91/postgres.git" }
55+
tokio-postgres = { git="https://github.com/fafhrd91/postgres.git", branch="ntex-1.0" }
5656

5757
[profile.release]
5858
opt-level = 3

frameworks/Rust/ntex/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ async fn main() -> std::io::Result<()> {
5555

5656
http::HttpService::build()
5757
.keep_alive(http::KeepAlive::Os)
58-
.client_timeout(Seconds(0))
58+
.client_timeout(Seconds::ZERO)
59+
.headers_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
60+
.payload_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
5961
.h1(web::App::new().service(json).service(plaintext).finish())
6062
})?
6163
.workers(num_cpus::get())

frameworks/Rust/ntex/src/main_db.rs

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ntex::http::header::{CONTENT_TYPE, SERVER};
77
use ntex::http::{HttpService, KeepAlive, Request, Response, StatusCode};
88
use ntex::service::{Service, ServiceCtx, ServiceFactory};
99
use ntex::web::{Error, HttpResponse};
10-
use ntex::{time::Seconds, util::BoxFuture, util::PoolId};
10+
use ntex::{time::Seconds, util::PoolId};
1111

1212
mod db;
1313
mod utils;
@@ -17,52 +17,49 @@ struct App(db::PgConnection);
1717
impl Service<Request> for App {
1818
type Response = Response;
1919
type Error = Error;
20-
type Future<'f> = BoxFuture<'f, Result<Response, Error>> where Self: 'f;
2120

22-
fn call<'a>(&'a self, req: Request, _: ServiceCtx<'a, Self>) -> Self::Future<'a> {
23-
Box::pin(async move {
24-
match req.path() {
25-
"/db" => {
26-
let body = self.0.get_world().await;
27-
let mut res = HttpResponse::with_body(StatusCode::OK, body.into());
28-
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
29-
res.headers_mut()
30-
.insert(CONTENT_TYPE, utils::HDR_JSON_CONTENT_TYPE);
31-
Ok(res)
32-
}
33-
"/fortunes" => {
34-
let body = self.0.tell_fortune().await;
35-
let mut res = HttpResponse::with_body(StatusCode::OK, body.into());
36-
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
37-
res.headers_mut()
38-
.insert(CONTENT_TYPE, utils::HDR_HTML_CONTENT_TYPE);
39-
Ok(res)
40-
}
41-
"/query" => {
42-
let worlds = self
43-
.0
44-
.get_worlds(utils::get_query_param(req.uri().query()))
45-
.await;
46-
let mut res = HttpResponse::with_body(StatusCode::OK, worlds.into());
47-
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
48-
res.headers_mut()
49-
.insert(CONTENT_TYPE, utils::HDR_JSON_CONTENT_TYPE);
50-
Ok(res)
51-
}
52-
"/update" => {
53-
let worlds = self
54-
.0
55-
.update(utils::get_query_param(req.uri().query()))
56-
.await;
57-
let mut res = HttpResponse::with_body(StatusCode::OK, worlds.into());
58-
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
59-
res.headers_mut()
60-
.insert(CONTENT_TYPE, utils::HDR_JSON_CONTENT_TYPE);
61-
Ok(res)
62-
}
63-
_ => Ok(Response::new(StatusCode::NOT_FOUND)),
21+
async fn call(&self, req: Request, _: ServiceCtx<'_, Self>) -> Result<Response, Error> {
22+
match req.path() {
23+
"/db" => {
24+
let body = self.0.get_world().await;
25+
let mut res = HttpResponse::with_body(StatusCode::OK, body.into());
26+
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
27+
res.headers_mut()
28+
.insert(CONTENT_TYPE, utils::HDR_JSON_CONTENT_TYPE);
29+
Ok(res)
6430
}
65-
})
31+
"/fortunes" => {
32+
let body = self.0.tell_fortune().await;
33+
let mut res = HttpResponse::with_body(StatusCode::OK, body.into());
34+
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
35+
res.headers_mut()
36+
.insert(CONTENT_TYPE, utils::HDR_HTML_CONTENT_TYPE);
37+
Ok(res)
38+
}
39+
"/query" => {
40+
let worlds = self
41+
.0
42+
.get_worlds(utils::get_query_param(req.uri().query()))
43+
.await;
44+
let mut res = HttpResponse::with_body(StatusCode::OK, worlds.into());
45+
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
46+
res.headers_mut()
47+
.insert(CONTENT_TYPE, utils::HDR_JSON_CONTENT_TYPE);
48+
Ok(res)
49+
}
50+
"/update" => {
51+
let worlds = self
52+
.0
53+
.update(utils::get_query_param(req.uri().query()))
54+
.await;
55+
let mut res = HttpResponse::with_body(StatusCode::OK, worlds.into());
56+
res.headers_mut().insert(SERVER, utils::HDR_SERVER);
57+
res.headers_mut()
58+
.insert(CONTENT_TYPE, utils::HDR_JSON_CONTENT_TYPE);
59+
Ok(res)
60+
}
61+
_ => Ok(Response::new(StatusCode::NOT_FOUND)),
62+
}
6663
}
6764
}
6865

@@ -73,13 +70,12 @@ impl ServiceFactory<Request> for AppFactory {
7370
type Error = Error;
7471
type Service = App;
7572
type InitError = ();
76-
type Future<'f> = BoxFuture<'f, Result<Self::Service, Self::InitError>>;
7773

78-
fn create(&self, _: ()) -> Self::Future<'_> {
74+
async fn create(&self, _: ()) -> Result<Self::Service, Self::InitError> {
7975
const DB_URL: &str =
8076
"postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world";
8177

82-
Box::pin(async move { Ok(App(db::PgConnection::connect(DB_URL).await)) })
78+
Ok(App(db::PgConnection::connect(DB_URL).await))
8379
}
8480
}
8581

@@ -97,6 +93,8 @@ async fn main() -> std::io::Result<()> {
9793
HttpService::build()
9894
.keep_alive(KeepAlive::Os)
9995
.client_timeout(Seconds(0))
96+
.headers_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
97+
.payload_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
10098
.h1(AppFactory)
10199
})?
102100
.workers(num_cpus::get())

0 commit comments

Comments
 (0)