Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upgrade reqwest to v0.12.3 #12

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ http-content-range = "0.1.2"
itertools = "0.12.1"
bisection = "0.1.0"
memmap2 = "0.9.0"
reqwest = { version = "0.11.22", default-features = false, features = ["stream"] }
reqwest-middleware = "0.2.4"
reqwest = { version = "0.12.3", default-features = false, features = ["stream"] }
reqwest-middleware = "0.3.0"
tokio = { version = "1.33.0", default-features = false }
tokio-stream = { version = "0.1.14", features = ["sync"] }
tokio-util = "0.7.9"
thiserror = "1.0.50"
tracing = "0.1.40"

[dev-dependencies]
axum = { version = "0.6.20", default-features = false, features = ["tokio"] }
axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1"] }
tokio = { version = "1.33.0", default-features = false, features = ["macros", "test-util"] }
tower-http = { version = "0.4.4", default-features = false, features = ["fs"] }
tower-http = { version = "0.5.2", default-features = false, features = ["fs"] }
async_zip = { version = "0.0.15", default-features = false, features = ["tokio"] }
assert_matches = "1.5.0"
rstest = { version = "0.18.2" }
Expand Down
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ mod test {
async fn async_range_reader_zip(#[case] check_method: CheckSupportMethod) {
// Spawn a static file server
let path = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("test-data");
let server = StaticDirectoryServer::new(&path);
let server = StaticDirectoryServer::new(&path)
.await
.expect("could not initialize server");

// check that file is there and has the right size
let filepath = path.join("andes-1.8.3-pyhd8ed1ab_0.conda");
Expand Down Expand Up @@ -776,7 +778,9 @@ mod test {
async fn async_range_reader(#[case] check_method: CheckSupportMethod) {
// Spawn a static file server
let path = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("test-data");
let server = StaticDirectoryServer::new(&path);
let server = StaticDirectoryServer::new(&path)
.await
.expect("could not initialize server");

// Construct an AsyncRangeReader
let (mut range, _) = AsyncHttpRangeReader::new(
Expand Down Expand Up @@ -820,7 +824,9 @@ mod test {

#[tokio::test]
async fn test_not_found() {
let server = StaticDirectoryServer::new(Path::new(env!("CARGO_MANIFEST_DIR")));
let server = StaticDirectoryServer::new(Path::new(env!("CARGO_MANIFEST_DIR")))
.await
.expect("could not initialize server");
let err = AsyncHttpRangeReader::new(
Client::new(),
server.url().join("not-found").unwrap(),
Expand Down
30 changes: 19 additions & 11 deletions src/static_directory_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl StaticDirectoryServer {
}

impl StaticDirectoryServer {
pub fn new(path: impl AsRef<Path>) -> Self {
pub async fn new(path: impl AsRef<Path>) -> Result<Self, StaticDirectoryServerError> {
let service = get_service(ServeDir::new(path));

// Create a router that will serve the static files
Expand All @@ -31,25 +31,27 @@ impl StaticDirectoryServer {
// port is very important because it enables creating multiple instances at the same time.
// We need this to be able to run tests in parallel.
let addr = SocketAddr::new([127, 0, 0, 1].into(), 0);
let server = axum::Server::bind(&addr).serve(app.into_make_service());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

axum::Server was removed in 0.7.0. The changelog suggests using axum::serve: https://github.com/tokio-rs/axum/blob/main/axum/CHANGELOG.md#070-27-november-2023.

let listener = tokio::net::TcpListener::bind(addr).await?;

// Get the address of the server so we can bind to it at a later stage.
let addr = server.local_addr();
let addr = listener.local_addr()?;

// Setup a graceful shutdown trigger which is fired when this instance is dropped.
let (tx, rx) = oneshot::channel();
let server = server.with_graceful_shutdown(async {
rx.await.ok();
});

// Spawn the server. Let go of the JoinHandle, we can use the graceful shutdown trigger to
// stop the server.
tokio::spawn(server);
// Spawn the server in the background.
tokio::spawn(async move {
let _ = axum::serve(listener, app.into_make_service())
.with_graceful_shutdown(async {
rx.await.ok();
})
.await;
});

Self {
Ok(Self {
local_addr: addr,
shutdown_sender: Some(tx),
}
})
}
}

Expand All @@ -60,3 +62,9 @@ impl Drop for StaticDirectoryServer {
}
}
}
/// Error type used for [`StaticDirectoryServerError`]
#[derive(Debug, thiserror::Error)]
pub enum StaticDirectoryServerError {
#[error(transparent)]
Io(#[from] std::io::Error),
}