From 74ebaf864831a343e78e911004d94cd3ff7424e0 Mon Sep 17 00:00:00 2001 From: Louis Pahlavi Date: Wed, 5 Nov 2025 16:42:57 +0100 Subject: [PATCH] Use `httpin` Docker image in CI --- .github/workflows/ci.yml | 7 +++++++ examples/http_canister/src/main.rs | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0cef132..d1a28b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,13 @@ jobs: integration-tests: runs-on: ubuntu-latest + services: + httpbin: + image: kennethreitz/httpbin + ports: + - 80:80 + env: + HTTPBIN_URL: http://localhost steps: - name: 'Checkout' uses: actions/checkout@v4 diff --git a/examples/http_canister/src/main.rs b/examples/http_canister/src/main.rs index 08d5378..9d8dbb9 100644 --- a/examples/http_canister/src/main.rs +++ b/examples/http_canister/src/main.rs @@ -1,4 +1,5 @@ //! Example of a canister using `canhttp` to issue HTTP requests. + use canhttp::{ cycles::{ChargeMyself, CyclesAccountingServiceBuilder}, http::HttpConversionLayer, @@ -11,7 +12,7 @@ use tower::{BoxError, Service, ServiceBuilder, ServiceExt}; /// Make an HTTP POST request. #[update] pub async fn make_http_post_request() -> String { - let request = http::Request::post("https://httpbin.org/anything") + let request = http::Request::post(format!("{}/anything", httpbin_base_url())) .max_response_bytes(1_000) .header("X-Id", "42") .body("Hello, World!".as_bytes().to_vec()) @@ -52,4 +53,10 @@ fn http_client( .service(Client::new_with_box_error()) } +fn httpbin_base_url() -> String { + option_env!("HTTPBIN_URL") + .unwrap_or_else(|| "https://httpbin.org") + .to_string() +} + fn main() {}