Skip to content

Commit e0fc1d0

Browse files
authored
Prepare ntex v3 release (#737)
* Rename ws apis * Remove debug prints * Change naming for WebSocketBuilder
1 parent 54dd921 commit e0fc1d0

File tree

11 files changed

+64
-95
lines changed

11 files changed

+64
-95
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ ntex-util = { path = "ntex-util" }
4545
ntex = "3.0.0"
4646
ntex-bytes = "1.4.1"
4747
ntex-codec = "1.1.0"
48-
ntex-io = "3.7.0"
48+
ntex-io = "3.7.1"
4949
ntex-dispatcher = "3.0.0"
50-
ntex-net = "3.5.2"
50+
ntex-net = "3.6.0"
5151
ntex-http = "1.0.0"
5252
ntex-router = "1.0.0"
53-
ntex-rt = "3.5.0"
53+
ntex-rt = "3.6.0"
5454
ntex-server = "3.6.0"
5555
ntex-service = "4.0.0"
5656
ntex-tls = "3.2.0"

ntex-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex-io"
3-
version = "3.7.0"
3+
version = "3.7.1"
44
authors = ["ntex contributors <team@ntex.rs>"]
55
description = "Utilities for abstracting io streams"
66
keywords = ["network", "framework", "async", "futures"]

ntex-io/src/cfg.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,13 @@ impl BufConfig {
264264
/// Resize buffer
265265
pub fn resize_min(&self, buf: &mut BytesMut, size: usize) {
266266
let mut avail = buf.remaining_mut();
267-
println!("resize: {avail} -- {size}");
268267
if avail < size {
269268
avail += self.high;
270269
let mut new_size = self.high + self.high;
271-
println!("resize 2: {avail} -- {new_size}");
272270
while avail < size {
273271
avail += self.high;
274272
new_size += self.high;
275273
}
276-
println!("resize 3: {new_size}");
277274
buf.reserve_capacity(new_size);
278275
}
279276
}

ntex/CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Changes
22

3-
## [3.0.0] 2026-02-xx
3+
## [3.0.0] 2026-02-02
44

55
* Refactor http control messages
66

7+
* Change naming for WebSocketBuilder
8+
79
* WebSocket subprotocol support #734
810

911
* Remove the need for mut in h2::Payload

ntex/src/http/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ impl TestServer {
439439
&self,
440440
path: &str,
441441
) -> Result<WsConnection<impl Filter>, WsClientError> {
442-
WsClient::build(self.url(path))
442+
WsClient::builder(self.url(path))
443443
.address(self.addr)
444444
.timeout(Seconds(30))
445-
.finish(SharedCfg::default())
445+
.build(SharedCfg::default())
446446
.await
447447
.unwrap()
448448
.connect()
@@ -477,12 +477,12 @@ impl TestServer {
477477
.set_alpn_protos(b"\x08http/1.1")
478478
.map_err(|e| log::error!("Cannot set alpn protocol: {e:?}"));
479479

480-
WsClient::build(self.url(path))
480+
WsClient::builder(self.url(path))
481481
.address(self.addr)
482482
.timeout(Seconds(30))
483483
.openssl(builder.build())
484484
.take()
485-
.finish(SharedCfg::default())
485+
.build(SharedCfg::default())
486486
.await
487487
.unwrap()
488488
.connect()

ntex/src/web/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -915,12 +915,12 @@ impl TestServer {
915915
.set_alpn_protos(b"\x08http/1.1")
916916
.map_err(|e| log::error!("Cannot set alpn protocol: {e:?}"));
917917

918-
WsClient::build(self.url(path))
918+
WsClient::builder(self.url(path))
919919
.address(self.addr)
920920
.timeout(Seconds(60))
921921
.openssl(builder.build())
922922
.take()
923-
.finish(SharedCfg::default())
923+
.build(SharedCfg::default())
924924
.await
925925
.unwrap()
926926
.connect()
@@ -932,10 +932,10 @@ impl TestServer {
932932
panic!("openssl feature is required")
933933
}
934934
} else {
935-
WsClient::build(self.url(path))
935+
WsClient::builder(self.url(path))
936936
.address(self.addr)
937937
.timeout(Seconds(60))
938-
.finish(SharedCfg::default())
938+
.build(SharedCfg::default())
939939
.await
940940
.unwrap()
941941
.connect()

ntex/src/web/ws.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,6 @@ pub fn subprotocols(req: &HttpRequest) -> impl Iterator<Item = &str> {
4747
})
4848
}
4949

50-
/// Start websocket service handling Frame messages with automatic control/stop logic.
51-
pub async fn start<T, F, Err>(req: HttpRequest, factory: F) -> Result<HttpResponse, Err>
52-
where
53-
T: ServiceFactory<Frame, WsSink, Response = Option<Message>> + 'static,
54-
T::Error: fmt::Debug,
55-
F: IntoServiceFactory<T, Frame, WsSink>,
56-
Err: From<T::InitError> + From<HandshakeError>,
57-
{
58-
start_using_subprotocol(req, None::<&str>, factory).await
59-
}
60-
6150
/// Start websocket service handling Frame messages with automatic control/stop logic,
6251
/// including the chosen subprotocol in the response.
6352
///
@@ -79,7 +68,7 @@ where
7968
/// ws::start_using_subprotocol(req, chosen, factory).await
8069
/// }
8170
/// ```
82-
pub async fn start_using_subprotocol<T, F, P, Err>(
71+
pub async fn start<T, F, P, Err>(
8372
req: HttpRequest,
8473
subprotocol: Option<P>,
8574
factory: F,
@@ -119,30 +108,15 @@ where
119108
}))
120109
});
121110

122-
start_using_subprotocol_with(req, subprotocol, factory).await
123-
}
124-
125-
/// Start websocket service handling raw DispatchItem messages requiring manual control/stop logic.
126-
pub async fn start_with<T, F, Err>(
127-
req: HttpRequest,
128-
factory: F,
129-
) -> Result<HttpResponse, Err>
130-
where
131-
T: ServiceFactory<DispatchItem<ws::Codec>, WsSink, Response = Option<Message>>
132-
+ 'static,
133-
T::Error: fmt::Debug,
134-
F: IntoServiceFactory<T, DispatchItem<ws::Codec>, WsSink>,
135-
Err: From<T::InitError> + From<HandshakeError>,
136-
{
137-
start_using_subprotocol_with(req, None::<&str>, factory).await
111+
start_with(req, subprotocol, factory).await
138112
}
139113

140114
/// Start websocket service handling raw DispatchItem messages requiring manual control/stop logic,
141115
/// including the chosen subprotocol in the response.
142116
///
143117
/// If `subprotocol` is `Some`, the `Sec-Websocket-Protocol` header will be included
144118
/// in the response with the chosen protocol. If `None`, the header is omitted.
145-
pub async fn start_using_subprotocol_with<T, F, P, Err>(
119+
pub async fn start_with<T, F, P, Err>(
146120
req: HttpRequest,
147121
subprotocol: Option<P>,
148122
factory: F,

ntex/src/ws/client.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct Inner<F, T> {
6363

6464
impl WsClient<Base, ()> {
6565
/// Create new websocket client builder
66-
pub fn build<U>(uri: U) -> WsClientBuilder<Base, Connector<Uri>>
66+
pub fn builder<U>(uri: U) -> WsClientBuilder<Base, Connector<Uri>>
6767
where
6868
Uri: TryFrom<U>,
6969
<Uri as TryFrom<U>>::Error: Into<HttpError>,
@@ -541,7 +541,7 @@ where
541541
}
542542

543543
/// Complete building process and construct websockets client.
544-
pub async fn finish<U: Into<SharedCfg>>(
544+
pub async fn build<U: Into<SharedCfg>>(
545545
&mut self,
546546
cfg: U,
547547
) -> Result<WsClient<F, T::Service>, WsClientBuilderError<T::InitError>> {
@@ -787,25 +787,25 @@ mod tests {
787787

788788
#[crate::rt_test]
789789
async fn test_debug() {
790-
let mut builder = WsClient::build("http://localhost")
790+
let mut builder = WsClient::builder("http://localhost")
791791
.header("x-test", "111")
792792
.take();
793793
let repr = format!("{builder:?}");
794794
assert!(repr.contains("WsClientBuilder"));
795795
assert!(repr.contains("x-test"));
796796

797-
let client = builder.finish(SharedCfg::default()).await.unwrap();
797+
let client = builder.build(SharedCfg::default()).await.unwrap();
798798
let repr = format!("{client:?}");
799799
assert!(repr.contains("WsClient"));
800800
assert!(repr.contains("x-test"));
801801
}
802802

803803
#[crate::rt_test]
804804
async fn header_override() {
805-
let req = WsClient::build("http://localhost")
805+
let req = WsClient::builder("http://localhost")
806806
.header(header::CONTENT_TYPE, "111")
807807
.set_header(header::CONTENT_TYPE, "222")
808-
.finish(SharedCfg::default())
808+
.build(SharedCfg::default())
809809
.await
810810
.unwrap();
811811

@@ -822,20 +822,20 @@ mod tests {
822822

823823
#[crate::rt_test]
824824
async fn basic_errs() {
825-
let err = WsClient::build("localhost")
826-
.finish(SharedCfg::default())
825+
let err = WsClient::builder("localhost")
826+
.build(SharedCfg::default())
827827
.await
828828
.err()
829829
.unwrap();
830830
assert!(matches!(err, WsClientBuilderError::MissingScheme));
831-
let err = WsClient::build("unknown://localhost")
832-
.finish(SharedCfg::default())
831+
let err = WsClient::builder("unknown://localhost")
832+
.build(SharedCfg::default())
833833
.await
834834
.err()
835835
.unwrap();
836836
assert!(matches!(err, WsClientBuilderError::UnknownScheme));
837-
let err = WsClient::build("/")
838-
.finish(SharedCfg::default())
837+
let err = WsClient::builder("/")
838+
.build(SharedCfg::default())
839839
.await
840840
.err()
841841
.unwrap();
@@ -844,9 +844,9 @@ mod tests {
844844

845845
#[crate::rt_test]
846846
async fn basic_auth() {
847-
let client = WsClient::build("http://localhost")
847+
let client = WsClient::builder("http://localhost")
848848
.basic_auth("username", Some("password"))
849-
.finish(SharedCfg::default())
849+
.build(SharedCfg::default())
850850
.await
851851
.unwrap();
852852
assert_eq!(
@@ -860,9 +860,9 @@ mod tests {
860860
"Basic dXNlcm5hbWU6cGFzc3dvcmQ="
861861
);
862862

863-
let client = WsClient::build("http://localhost")
863+
let client = WsClient::builder("http://localhost")
864864
.basic_auth("username", None)
865-
.finish(SharedCfg::default())
865+
.build(SharedCfg::default())
866866
.await
867867
.unwrap();
868868
assert_eq!(
@@ -894,9 +894,9 @@ mod tests {
894894
#[crate::rt_test]
895895
#[allow(clippy::let_underscore_future)]
896896
async fn bearer_auth() {
897-
let client = WsClient::build("http://localhost")
897+
let client = WsClient::builder("http://localhost")
898898
.bearer_auth("someS3cr3tAutht0k3n")
899-
.finish(SharedCfg::default())
899+
.build(SharedCfg::default())
900900
.await
901901
.unwrap();
902902
assert_eq!(
@@ -930,7 +930,7 @@ mod tests {
930930
#[cfg(feature = "cookie")]
931931
#[crate::rt_test]
932932
async fn basics() {
933-
let mut builder = WsClient::build("http://localhost/")
933+
let mut builder = WsClient::builder("http://localhost/")
934934
.origin("test-origin")
935935
.max_frame_size(100)
936936
.server_mode()
@@ -947,7 +947,7 @@ mod tests {
947947
assert!(builder.inner.as_ref().unwrap().server_mode);
948948
assert_eq!(builder.protocols, Some("v1,v2".to_string()));
949949

950-
let client = builder.finish(SharedCfg::default()).await.unwrap();
950+
let client = builder.build(SharedCfg::default()).await.unwrap();
951951
assert_eq!(
952952
client.head.headers.get(header::CONTENT_TYPE).unwrap(),
953953
header::HeaderValue::from_static("json")
@@ -956,20 +956,20 @@ mod tests {
956956
let _ = client.connect().await;
957957

958958
assert!(
959-
WsClient::build("/")
960-
.finish(SharedCfg::default())
959+
WsClient::builder("/")
960+
.build(SharedCfg::default())
961961
.await
962962
.is_err()
963963
);
964964
assert!(
965-
WsClient::build("http:///test")
966-
.finish(SharedCfg::default())
965+
WsClient::builder("http:///test")
966+
.build(SharedCfg::default())
967967
.await
968968
.is_err()
969969
);
970970
assert!(
971-
WsClient::build("hmm://test.com/")
972-
.finish(SharedCfg::default())
971+
WsClient::builder("hmm://test.com/")
972+
.build(SharedCfg::default())
973973
.await
974974
.is_err()
975975
);

ntex/tests/http_openssl.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@ where
2121
S: Stream<Item = Result<Bytes, PayloadError>>,
2222
{
2323
let body = stream
24-
.map(|res| {
25-
if let Ok(chunk) = res {
26-
chunk
27-
} else {
28-
println!("======== {res:?}");
29-
panic!()
30-
}
31-
})
24+
.map(|res| if let Ok(chunk) = res { chunk } else { panic!() })
3225
.fold(BytesMut::new(), move |mut body, chunk| async move {
3326
body.extend_from_slice(&chunk);
3427
body

ntex/tests/http_ws_client.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ async fn test_keepalive_timeout() {
168168
.await;
169169

170170
// client service
171-
let con = ws::WsClient::build(srv.url("/"))
171+
let con = ws::WsClient::builder(srv.url("/"))
172172
.address(srv.addr())
173173
.timeout(Seconds(30))
174-
.finish(SharedCfg::default())
174+
.build(SharedCfg::default())
175175
.await
176176
.unwrap()
177177
.connect()
@@ -203,8 +203,9 @@ async fn test_upgrade_handler_with_await() {
203203
// some async context switch
204204
ntex::time::sleep(ntex::time::Seconds::ZERO).await;
205205

206-
web::ws::start::<_, _, web::Error>(
206+
web::ws::start::<_, _, _, web::Error>(
207207
req,
208+
None::<&str>,
208209
fn_factory_with_config(|_| async {
209210
Ok::<_, web::Error>(fn_service(service))
210211
}),
@@ -215,10 +216,10 @@ async fn test_upgrade_handler_with_await() {
215216
})
216217
.await;
217218

218-
let _ = ws::WsClient::build(srv.url("/"))
219+
let _ = ws::WsClient::builder(srv.url("/"))
219220
.address(srv.addr())
220221
.timeout(Seconds(1))
221-
.finish(SharedCfg::default())
222+
.build(SharedCfg::default())
222223
.await
223224
.unwrap()
224225
.connect()

0 commit comments

Comments
 (0)