Skip to content

Commit b5c7079

Browse files
committed
Merge branch 'release/v3.0.0'
2 parents 568725a + 72684a8 commit b5c7079

File tree

5 files changed

+18
-77
lines changed

5 files changed

+18
-77
lines changed

Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "routerify-websocket"
3-
version = "1.0.0"
3+
version = "3.0.0"
44
description = "The websocket support for the Routerify library."
55
homepage = "https://github.com/routerify/routerify-websocket"
66
repository = "https://github.com/routerify/routerify-websocket"
@@ -25,18 +25,17 @@ json = ["serde", "serde_json"]
2525
[dependencies]
2626
log = "0.4"
2727
derive_more = "0.99"
28-
routerify = "1.1"
29-
hyper = "0.13"
28+
routerify = "3.0"
29+
hyper = "0.14"
3030
headers = "0.3"
31-
tokio-tungstenite = { version = "0.10", default-features = false }
31+
tokio-tungstenite = { version = "0.16", default-features = false }
3232
futures = { version = "0.3", default-features = false }
33-
tokio = { version = "0.2", features = ["rt-core"] }
33+
tokio = { version = "1.0", features = ["rt"] }
3434

3535
serde = { version = "1.0", optional = true }
3636
serde_json = { version = "1.0", optional = true }
3737

3838
[dev-dependencies]
39-
tokio = { version = "0.2", features = ["full"] }
40-
stream-body = "0.1"
39+
tokio = { version = "1.0", features = ["full"] }
4140
serde = { version = "1.0", features = ["derive"] }
42-
tokio-tungstenite = { version = "0.10", features = ["tls"] }
41+
tokio-tungstenite = { version = "0.16" }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Add this to your `Cargo.toml` file:
1515

1616
```toml
1717
[dependencies]
18-
routerify = "1.1"
19-
routerify-websocket = "1.0"
18+
routerify = "3"
19+
routerify-websocket = "3"
2020
```
2121

2222
## Example

examples/test.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
use futures::{Sink, SinkExt, StreamExt};
1+
use futures::{SinkExt, StreamExt};
22
use hyper::{Body, Request, Response, Server};
33
use routerify::prelude::*;
44
use routerify::{Middleware, Router, RouterService};
5-
use routerify_websocket::{upgrade_ws, upgrade_ws_with_config, Message, WebSocket, WebSocketConfig};
5+
use routerify_websocket::{upgrade_ws, WebSocket};
66
use serde::{Deserialize, Serialize};
77
use std::{convert::Infallible, net::SocketAddr};
8-
use tokio_tungstenite::{
9-
tungstenite::protocol::{frame::coding::CloseCode, CloseFrame, Message as ClientMessage},
10-
WebSocketStream,
11-
};
8+
use tokio_tungstenite::tungstenite::protocol::Message as ClientMessage;
129

1310
#[derive(Serialize, Deserialize, Debug)]
1411
struct User {
@@ -19,7 +16,7 @@ struct User {
1916
async fn ws_handler(ws: WebSocket) {
2017
println!("new websocket connection: {}", ws.remote_addr());
2118

22-
let (mut tx, mut rx) = ws.split();
19+
let (_tx, mut rx) = ws.split();
2320

2421
while let Some(msg) = rx.next().await {
2522
let msg = msg.unwrap();
@@ -60,7 +57,7 @@ async fn main() {
6057
let server = Server::bind(&addr).serve(service);
6158

6259
tokio::spawn(async move {
63-
tokio::time::delay_for(tokio::time::Duration::from_secs(3)).await;
60+
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
6461

6562
let (mut ws, resp) = tokio_tungstenite::connect_async("ws://127.0.0.1:3001/ws")
6663
.await
@@ -73,7 +70,7 @@ async fn main() {
7370

7471
ws.close(None).await.unwrap();
7572

76-
tokio::time::delay_for(tokio::time::Duration::from_secs(3)).await;
73+
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
7774
});
7875

7976
println!("App is running on: {}", addr);

examples/test_stream_body.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/upgrade.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use std::future::Future;
5757
pub fn upgrade_ws_with_config<H, R, B, E>(
5858
handler: H,
5959
config: WebSocketConfig,
60-
) -> impl FnMut(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
60+
) -> impl Fn(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
6161
where
6262
H: Fn(WebSocket) -> R + Copy + Send + Sync + 'static,
6363
R: Future<Output = ()> + Send + 'static,
@@ -76,7 +76,7 @@ where
7676
}
7777

7878
tokio::spawn(async move {
79-
match req.into_body().on_upgrade().await {
79+
match hyper::upgrade::on(req).await {
8080
Ok(upgraded) => {
8181
handler(WebSocket::from_raw_socket(upgraded, remote_addr, config).await).await;
8282
}
@@ -146,7 +146,7 @@ where
146146
/// ```
147147
pub fn upgrade_ws<H, R, B, E>(
148148
handler: H,
149-
) -> impl FnMut(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
149+
) -> impl Fn(Request<hyper::Body>) -> Ready<Result<Response<B>, E>> + Send + Sync + 'static
150150
where
151151
H: Fn(WebSocket) -> R + Copy + Send + Sync + 'static,
152152
R: Future<Output = ()> + Send + 'static,

0 commit comments

Comments
 (0)