HELP! Upgrade to 0.9.4: how to handle RouterResponse<BoxStream<'static, ResponseBody>> compile errors???? #1249
Answered
by
o0Ignition0o
golfingal72
asked this question in
Q&A
-
I had to update to 0.9.4 to get the fix for the clap issue.. I have a plugin that is working with the RouterResponse and now it won't work... the old code looks like this and now that the RouterResponse object has changed, i don't know how to handle.. see compile errors below .map_response(|mut resp:RouterResponse| {
let mut debug_query = false;
if let Ok(Some(data)) = resp.context.get::<_, bool>("graphDebug") {
debug_query = data;
}
if (debug_query) {
log::info!(target: "app::debug", "Final Response: {:?}", resp);
log::info!(target: "app::debug", "Final Response: {:?}", resp.response.body());
log::info!(target: "app::debug", "Final Response Headers: {:?}", resp.response.headers());
log::info!(target: "app::debug", "Final Response: {:?}", resp.context);
}
// do any Set-Cookies for response
if let Ok(Some(data)) = resp.context.get::<_, CookieContext>("cookie_context") {
if (data.has_set_cookies) {
let mut set_cookie_offset = 0;
for existing_set_cookie in data.response_set_cookies {
match existing_set_cookie {
Some(value) => {
let hv = HeaderValue::from_str(&value).unwrap();
resp.response.headers_mut().append("Set-Cookie", hv);
},
None => {}
}
set_cookie_offset += 1;
}
}
}
let transaction_id = resp.context.get::<_, String>("transaction_id").unwrap().unwrap_or("bugaboo".to_string()).to_string();
if let Ok(Some(mut timer)) = resp.context.get::<_, GraphTimer>(&transaction_id) {
timer.status = Some(resp.response.status().as_u16());
match resp.response.body() {
ResponseBody::RawJSON(_) => {}
ResponseBody::GraphQL(res) => {
match &res.data {
Some(data) => timer.len = Some(data.to_string().len() as u64),
None => ()
}
}
ResponseBody::Text(_) => {}
}
timer.print_timer();
}
|
Beta Was this translation helpful? Give feedback.
Answered by
o0Ignition0o
Jun 15, 2022
Replies: 2 comments 10 replies
-
ping o0Ignition0o |
Beta Was this translation helpful? Give feedback.
10 replies
-
This repository provides you with a working example of stream management, with more advanced things such as dealing with context |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
o0Ignition0o
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This repository provides you with a working example of stream management, with more advanced things such as dealing with context