Skip to content

Commit 9d31236

Browse files
author
SvetlinZarev-SAP
authored
Add support for nested HTTP callouts. (#56)
Signed-off-by: Svetlin Zarev <[email protected]>
1 parent 4cb2db7 commit 9d31236

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/dispatcher.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,24 @@ impl Dispatcher {
345345
body_size: usize,
346346
num_trailers: usize,
347347
) {
348-
if let Some(context_id) = self.callouts.borrow_mut().remove(&token_id) {
349-
if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
350-
self.active_id.set(context_id);
351-
hostcalls::set_effective_context(context_id).unwrap();
352-
http_stream.on_http_call_response(token_id, num_headers, body_size, num_trailers)
353-
} else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) {
354-
self.active_id.set(context_id);
355-
hostcalls::set_effective_context(context_id).unwrap();
356-
stream.on_http_call_response(token_id, num_headers, body_size, num_trailers)
357-
} else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) {
358-
self.active_id.set(context_id);
359-
hostcalls::set_effective_context(context_id).unwrap();
360-
root.on_http_call_response(token_id, num_headers, body_size, num_trailers)
361-
}
362-
} else {
363-
panic!("invalid token_id")
348+
let context_id = self
349+
.callouts
350+
.borrow_mut()
351+
.remove(&token_id)
352+
.expect("invalid token_id");
353+
354+
if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
355+
self.active_id.set(context_id);
356+
hostcalls::set_effective_context(context_id).unwrap();
357+
http_stream.on_http_call_response(token_id, num_headers, body_size, num_trailers)
358+
} else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) {
359+
self.active_id.set(context_id);
360+
hostcalls::set_effective_context(context_id).unwrap();
361+
stream.on_http_call_response(token_id, num_headers, body_size, num_trailers)
362+
} else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) {
363+
self.active_id.set(context_id);
364+
hostcalls::set_effective_context(context_id).unwrap();
365+
root.on_http_call_response(token_id, num_headers, body_size, num_trailers)
364366
}
365367
}
366368
}

0 commit comments

Comments
 (0)