Skip to content
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
30 changes: 16 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ reqwest = "0.12"

ic-cdk = "0.17"
ic-cdk-macros = "0.17"
ic-agent = { git = "https://github.com/dfinity/agent-rs", rev = "f34acedb5539838ffdbd4cf49a0832303977293f" }
ic-utils = { git = "https://github.com/dfinity/agent-rs", rev = "f34acedb5539838ffdbd4cf49a0832303977293f" }
ic-agent = "0.44"
ic-utils = "0.44"
candid = "0.10"
pocket-ic = "6.0"
assert_matches = "1"
Expand Down
53 changes: 19 additions & 34 deletions examples/http-gateway/canister/src/custom_assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,44 +111,29 @@ fn current_chunk_index(resp: &HttpResponse) -> usize {
}

fn chunk_corruption_requested(req: &HttpRequest) -> Option<usize> {
if let Some(corrupted_chunk_index) = get_header_value(req.headers(), "Test-CorruptChunkAtIndex")
{
Some(
corrupted_chunk_index
.parse()
.expect("invalid index of chunk to corrupt"),
)
} else {
None
}
get_header_value(req.headers(), "Test-CorruptChunkAtIndex").map(|corrupted_chunk_index| {
corrupted_chunk_index
.parse()
.expect("invalid index of chunk to corrupt")
})
}

fn cert_corruption_requested(req: &HttpRequest) -> Option<usize> {
if let Some(corrupted_cert_chunk_index) =
get_header_value(req.headers(), "Test-CorruptCertificateAtIndex")
{
Some(
get_header_value(req.headers(), "Test-CorruptCertificateAtIndex").map(
|corrupted_cert_chunk_index| {
corrupted_cert_chunk_index
.parse()
.expect("invalid index of chunk to corrupt the certificate"),
)
} else {
None
}
.expect("invalid index of chunk to corrupt the certificate")
},
)
}

fn chunk_swap_requested(req: &HttpRequest) -> Option<usize> {
if let Some(chunk_index_to_swap) =
get_header_value(req.headers(), "Test-SwapChunkAtIndexWithNext")
{
Some(
chunk_index_to_swap
.parse()
.expect("invalid index of chunk to swap"),
)
} else {
None
}
get_header_value(req.headers(), "Test-SwapChunkAtIndexWithNext").map(|chunk_index_to_swap| {
chunk_index_to_swap
.parse()
.expect("invalid index of chunk to swap")
})
}

fn get_header_value(headers: &[HeaderField], header_name: &str) -> Option<String> {
Expand Down Expand Up @@ -178,10 +163,10 @@ fn get_content_range_begin(content_range_header_value: &str) -> usize {
content_range_header_value
);
}
let range_begin = str_value_parts[0].parse::<usize>().expect(&format!(
"Invalid range_begin in: {}",
content_range_header_value
));
let range_begin = str_value_parts[0]
.parse::<usize>()
.unwrap_or_else(|_| panic!("Invalid range_begin in: {content_range_header_value}"));

// Note: skipping the check whether range_end and total_length are sane.
range_begin
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ic-http-gateway/src/client/http_gateway_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct HttpGatewayClient {
agent: Agent,
}

impl HttpGatewayClient {
impl<'a> HttpGatewayClient {
pub fn new(args: HttpGatewayClientArgs) -> Self {
Self { agent: args.agent }
}
Expand All @@ -23,7 +23,7 @@ impl HttpGatewayClient {
Default::default()
}

pub fn request(&self, args: HttpGatewayRequestArgs) -> HttpGatewayRequestBuilder {
pub fn request(&'a self, args: HttpGatewayRequestArgs) -> HttpGatewayRequestBuilder<'a> {
HttpGatewayRequestBuilder::new(HttpGatewayRequestBuilderArgs {
request_args: args,
agent: &self.agent,
Expand Down