diff --git a/bitreq/.github/workflows/lint.yml b/bitreq/.github/workflows/lint.yml deleted file mode 100644 index 9d7048f3..00000000 --- a/bitreq/.github/workflows/lint.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: lint - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -env: - CARGO_TERM_COLOR: always - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Set Toolchain - # https://github.com/dtolnay/rust-toolchain - uses: dtolnay/rust-toolchain@stable - - name: Run rustfmt - # rustfmt defaults to edition 2015 it seems. - run: rustfmt --check --edition=2018 src/lib.rs - - name: Run cargo doc - run: cargo doc --features "punycode proxy https" - - name: Run clippy - run: | - cargo clippy --all-targets --features "punycode proxy https-rustls" -- --no-deps -D warnings - cargo clippy --all-targets --features "punycode proxy https-rustls-probe" -- --no-deps -D warnings diff --git a/bitreq/.github/workflows/msrv.yml b/bitreq/.github/workflows/msrv.yml deleted file mode 100644 index aede3509..00000000 --- a/bitreq/.github/workflows/msrv.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: msrv - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - schedule: - - cron: "47 5 * * 6" - -env: - CARGO_TERM_COLOR: always - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Checkout Toolchain - uses: dtolnay/rust-toolchain@1.75 - - name: Running test script - run: | - cargo test diff --git a/bitreq/.github/workflows/unit-tests.yml b/bitreq/.github/workflows/unit-tests.yml deleted file mode 100644 index d91899be..00000000 --- a/bitreq/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: unit-tests - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -env: - CARGO_TERM_COLOR: always - -jobs: - test-linux: - runs-on: ubuntu-latest - steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Set Toolchain - # https://github.com/dtolnay/rust-toolchain - uses: dtolnay/rust-toolchain@stable - - name: Build - run: cargo build - - name: Test - run: | - cargo test - cargo test --features punycode - cargo test --features proxy - cargo test --features urlencoding - cargo test --features https - test-windows: - runs-on: windows-latest - steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Set Toolchain - uses: dtolnay/rust-toolchain@stable - - name: Build - run: cargo build - - name: Test - run: | - cargo test - cargo test --features punycode - cargo test --features proxy - cargo test --features urlencoding - cargo test --features https - cargo test --features "punycode proxy urlencoding https" - test-macos: - runs-on: macos-latest - steps: - - name: Checkout Crate - uses: actions/checkout@v3 - - name: Set Toolchain - uses: dtolnay/rust-toolchain@stable - - name: Build - run: cargo build - - name: Test - run: | - cargo test - cargo test --features punycode - cargo test --features proxy - cargo test --features urlencoding - cargo test --features https - cargo test --features "punycode proxy urlencoding https" diff --git a/bitreq/Cargo.toml b/bitreq/Cargo.toml index 4629c3e0..53b19def 100644 --- a/bitreq/Cargo.toml +++ b/bitreq/Cargo.toml @@ -50,7 +50,7 @@ https = ["https-rustls"] https-rustls = ["rustls", "webpki-roots", "rustls-webpki"] https-rustls-probe = ["rustls", "rustls-native-certs"] json-using-serde = ["serde", "serde_json"] -proxy = ["base64"] +proxy = ["base64", "std"] async = ["tokio", "std"] async-https = ["async", "https-rustls", "tokio-rustls"] diff --git a/bitreq/README.md b/bitreq/README.md index 90e940b3..0acc219b 100644 --- a/bitreq/README.md +++ b/bitreq/README.md @@ -1,8 +1,6 @@ # bitreq - forked from minreq [![Crates.io](https://img.shields.io/crates/d/bitreq.svg)](https://crates.io/crates/bitreq) [![Documentation](https://docs.rs/bitreq/badge.svg)](https://docs.rs/bitreq) -![Unit tests](https://github.com/tcharding/bitreq/actions/workflows/unit-tests.yml/badge.svg) -![MSRV](https://github.com/tcharding/bitreq/actions/workflows/msrv.yml/badge.svg) This crate is a fork for the very nice [minreq](https://github.com/neonmoe/minreq). I chose to fork and diff --git a/bitreq/contrib/test_vars.sh b/bitreq/contrib/test_vars.sh new file mode 100644 index 00000000..5e9177e8 --- /dev/null +++ b/bitreq/contrib/test_vars.sh @@ -0,0 +1,14 @@ +# No shebang, this file should not be executed. +# shellcheck disable=SC2148 +# +# disable verify unused vars, despite the fact that they are used when sourced +# shellcheck disable=SC2034 + +# Test all these features with "std" enabled. +FEATURES_WITH_STD="log https https-rustls proxy async async-https" + +# Test all these features without "std" enabled. +FEATURES_WITHOUT_STD="log https https-rustls" + +# Run these examples. +EXAMPLES="" diff --git a/bitreq/examples/no-std.rs b/bitreq/examples/no-std.rs index 1ebffc54..f682bc83 100644 --- a/bitreq/examples/no-std.rs +++ b/bitreq/examples/no-std.rs @@ -1,7 +1,5 @@ //! This is a simple example to demonstrate the usage of this library. -#![cfg(feature = "std")] - const _RESPONSE: &str = r#" @@ -16,7 +14,7 @@ const _RESPONSE: &str = r#" margin: 0; padding: 0; font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; - + } div { width: 600px; @@ -36,7 +34,7 @@ const _RESPONSE: &str = r#" width: auto; } } - + diff --git a/bitreq/src/connection/rustls_stream.rs b/bitreq/src/connection/rustls_stream.rs index f0fe7ba6..23854501 100644 --- a/bitreq/src/connection/rustls_stream.rs +++ b/bitreq/src/connection/rustls_stream.rs @@ -5,6 +5,7 @@ use alloc::sync::Arc; use core::convert::TryFrom; use std::io::{self, Write}; use std::net::TcpStream; +use std::sync::OnceLock; use rustls::{self, ClientConfig, ClientConnection, RootCertStore, ServerName, StreamOwned}; #[cfg(feature = "rustls-webpki")] @@ -15,8 +16,9 @@ use crate::Error; pub type SecuredStream = StreamOwned; -#[allow(clippy::incompatible_msrv)] // We only guarantee MSRV for a subset of features. -static CONFIG: std::sync::LazyLock> = std::sync::LazyLock::new(|| { +static CONFIG: OnceLock> = OnceLock::new(); + +fn build_client_config() -> Arc { let mut root_certificates = RootCertStore::empty(); // Try to load native certs @@ -44,7 +46,7 @@ static CONFIG: std::sync::LazyLock> = std::sync::LazyLock::new .with_root_certificates(root_certificates) .with_no_client_auth(); Arc::new(config) -}); +} pub fn create_secured_stream(conn: &Connection) -> Result { // Rustls setup @@ -54,8 +56,8 @@ pub fn create_secured_stream(conn: &Connection) -> Result { Ok(result) => result, Err(err) => return Err(Error::IoError(io::Error::new(io::ErrorKind::Other, err))), }; - let sess = - ClientConnection::new(CONFIG.clone(), dns_name).map_err(Error::RustlsCreateConnection)?; + let sess = ClientConnection::new(CONFIG.get_or_init(build_client_config).clone(), dns_name) + .map_err(Error::RustlsCreateConnection)?; // Connect #[cfg(feature = "log")] diff --git a/contrib/crates.sh b/contrib/crates.sh index 1362f549..c084fcb1 100755 --- a/contrib/crates.sh +++ b/contrib/crates.sh @@ -2,4 +2,4 @@ # shellcheck disable=SC2148 # Crates in this workspace to test. -CRATES=("types" "client" "jsonrpc") +CRATES=("bitreq" "client" "jsonrpc" "types")