Skip to content

Commit e5c6386

Browse files
Bump tower to v0.5 (#4075)
1 parent b012a75 commit e5c6386

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

crates/example-tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
2323
tokio = { version = "1.29.1", features = ["macros", "net", "time"] }
2424
tokio-tungstenite = "0.23"
25-
tower = { version = "0.4.13", features = ["make"] }
25+
tower = { version = "0.5", features = ["make", "util"] }
2626
tower-http = { version = "0.5", features = ["fs", "util", "set-header"] }

crates/example-tests/src/lib.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{env, str};
88

99
use anyhow::{bail, Context};
1010
use futures_util::{future, SinkExt, StreamExt};
11-
use http::{HeaderName, HeaderValue};
11+
use http::{HeaderName, HeaderValue, Response};
1212
use hyper_util::rt::{TokioExecutor, TokioIo};
1313
use hyper_util::server::conn::auto::Builder;
1414
use hyper_util::service::TowerToHyperService;
@@ -24,8 +24,8 @@ use tokio::time::timeout;
2424
use tokio_tungstenite::tungstenite::{self, Message};
2525
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
2626
use tower::ServiceBuilder;
27+
use tower_http::services::fs::ServeFileSystemResponseBody;
2728
use tower_http::services::ServeDir;
28-
use tower_http::ServiceBuilderExt;
2929

3030
/// A command sent from the client to the server.
3131
#[derive(Serialize)]
@@ -330,14 +330,17 @@ pub async fn test_example(
330330
// Serve the path.
331331
let service = TowerToHyperService::new(
332332
ServiceBuilder::new()
333-
.override_response_header(
334-
HeaderName::from_static("cross-origin-opener-policy"),
335-
HeaderValue::from_static("same-origin"),
336-
)
337-
.override_response_header(
338-
HeaderName::from_static("cross-origin-embedder-policy"),
339-
HeaderValue::from_static("require-corp"),
340-
)
333+
.map_response(|mut response: Response<ServeFileSystemResponseBody>| {
334+
response.headers_mut().insert(
335+
HeaderName::from_static("cross-origin-opener-policy"),
336+
HeaderValue::from_static("same-origin"),
337+
);
338+
response.headers_mut().insert(
339+
HeaderName::from_static("cross-origin-embedder-policy"),
340+
HeaderValue::from_static("require-corp"),
341+
);
342+
response
343+
})
341344
.service(ServeDir::new(path)),
342345
);
343346

0 commit comments

Comments
 (0)