From b461232635bd44c6c1a589cbdab896d98e4bfea3 Mon Sep 17 00:00:00 2001 From: Natalia Maximo Date: Tue, 14 Jan 2025 16:58:18 -0500 Subject: [PATCH 1/4] enable using environment variable for passing in url --- Cargo.lock | 14 +++++++------- Cargo.toml | 2 +- README.md | 4 ++-- src/main.rs | 8 ++++++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4631f0..a31f5d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,12 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "cc" -version = "1.1.30" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "shlex", ] @@ -37,9 +37,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.160" +version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b21006cd1874ae9e650973c565615676dc4a274c965bb0a73796dac838ce4f" +checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" [[package]] name = "log" @@ -49,9 +49,9 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "minreq" -version = "2.12.0" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "763d142cdff44aaadd9268bebddb156ef6c65a0e13486bb81673cf2d8739f9b0" +checksum = "36a8e50e917e18a37d500d27d40b7bc7d127e71c0c94fb2d83f43b4afd308390" dependencies = [ "log", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 4b799bd..0eab2d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["http", "client", "minimal"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -minreq = "2.12.0" +minreq = "2.13.0" [features] default = [] diff --git a/README.md b/README.md index 2156462..aab18b6 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ Let's compare the binary size against other popular ones, specifically against ` | ------------------------ | ----- | | `curl` | 6.1mb | | `wget` | 1.4mb | -| `httpget`, no TLS | 531kb | -| `httpget`, with `rustls` | 1.2mb | +| `httpget`, no TLS | 519kb | +| `httpget`, with `rustls` | 1.3mb | So, all in all, it's quite minimal. diff --git a/src/main.rs b/src/main.rs index 25603dc..f5bc45e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,13 @@ fn main() -> ExitCode { panic!("Too many arguments!") } - let endpoint = args.last().unwrap(); + let endpoint = if args.len() == 2 { + args.last().unwrap().to_owned() + } else { + env::var("HTTPGET_ENDPOINT").unwrap() + }; - let res = run(endpoint); + let res = run(&endpoint); if res.is_err() { println!("{}", res.unwrap_err()); From 254d18cf00eed0e75752d845e208f3974fa839b7 Mon Sep 17 00:00:00 2001 From: Natalia Maximo Date: Tue, 14 Jan 2025 17:02:26 -0500 Subject: [PATCH 2/4] add documentation for using endpoint through environment variable --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index aab18b6..6a2f2ff 100644 --- a/README.md +++ b/README.md @@ -86,3 +86,7 @@ The regular binary and the TLS binary are available through Github Releases, and This project is published on [crates.io](https://crates.io/crates/httpget), and can be installed using `cargo` with the command `cargo install httpget`. This will **not** produce a statically-linked binary: for that, you must ensure that you've installed the correct `*-unknown-linux-musl` target. You can also clone this repository and run `cargo install --path .` to install through Cargo + +## Specifying Endpoint + +There are two supported ways to pass an endpoint to `httpget`. The first is to pass it explicitly (e.g. `httpget http://example.com/`). The second is to specify the endpoint in the `HTTPGET_ENDPOINT` environment variable, and call `httpget` with no arguments. From 8d6e18df9b30535a47b6ae0e3d87eaee17b63988 Mon Sep 17 00:00:00 2001 From: Natalia Maximo Date: Tue, 14 Jan 2025 17:08:19 -0500 Subject: [PATCH 3/4] fix audit step --- .github/workflows/release.yaml | 6 ++++-- .github/workflows/test.yaml | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4ae346a..643a794 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -15,6 +15,7 @@ jobs: permissions: contents: write packages: write + checks: write steps: - name: Checkout repository @@ -51,8 +52,9 @@ jobs: - name: Lint the code run: cargo clippy - - name: Run the security audit check - run: cargo audit + - uses: rustsec/audit-check@v1.4.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} - name: Set the crate version run: cargo install cargo-edit --bin cargo-set-version && cargo set-version ${{ env.VERSION }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 085abec..507635c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -59,6 +59,8 @@ jobs: test: runs-on: ubuntu-latest + permissions: + checks: write steps: - name: Checkout repository @@ -90,8 +92,9 @@ jobs: - name: Lint the code run: cargo clippy - - name: Run the security audit check - run: cargo audit + - uses: rustsec/audit-check@v1.4.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} - name: Run the tests with the static target for the debug build run: cross test --target x86_64-unknown-linux-musl From 84d365f6f64d5bd8b7dcb33be6eedc40152a4230 Mon Sep 17 00:00:00 2001 From: Natalia Maximo Date: Tue, 14 Jan 2025 17:10:10 -0500 Subject: [PATCH 4/4] Use expect function for better failure case messaging Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f5bc45e..42fc1e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ fn main() -> ExitCode { let endpoint = if args.len() == 2 { args.last().unwrap().to_owned() } else { - env::var("HTTPGET_ENDPOINT").unwrap() + env::var("HTTPGET_ENDPOINT").expect("Environment variable HTTPGET_ENDPOINT not set") }; let res = run(&endpoint);