diff --git a/src/app.rs b/src/app.rs index 571f2b0..c2bbf9e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -436,7 +436,7 @@ impl<'a> App<'a> { AppOptions::Outfile(outfile) => self.command.as_mut().unwrap().set_outfile(&outfile), - AppOptions::Cookie(cookie) => self.command.as_mut().unwrap().add_cookie(cookie), + AppOptions::Cookie(cookie) => self.command.as_mut().unwrap().add_cookie(&cookie), AppOptions::RecDownload(i) => self.command.as_mut().unwrap().set_rec_download_level(i), @@ -507,7 +507,7 @@ impl<'a> App<'a> { AppOptions::Cookie(_) => { if let AppOptions::Cookie(ref mut cookie) = opt { option.replace_value(cookie.clone()); - self.command.as_mut().unwrap().add_cookie(cookie.clone()); + self.command.as_mut().unwrap().add_cookie(cookie); } } AppOptions::CaPath(_) => { diff --git a/src/request/command.rs b/src/request/command.rs index 86fc439..4006e30 100644 --- a/src/request/command.rs +++ b/src/request/command.rs @@ -94,7 +94,7 @@ impl<'a> CmdOpts for Cmd<'a> { } impl<'a> CurlOpts for Cmd<'a> { - fn add_cookie(&mut self, cookie: String) { + fn add_cookie(&mut self, cookie: &str) { if let Cmd::Curl(curl) = self { curl.add_cookie(cookie); } @@ -264,7 +264,7 @@ pub trait CurlOpts { fn set_content_header(&mut self, kind: HeaderKind); fn set_request_body(&mut self, body: &str); fn set_upload_file(&mut self, file: &str); - fn add_cookie(&mut self, cookie: String); + fn add_cookie(&mut self, cookie: &str); fn set_follow_redirects(&mut self, opt: bool); fn set_proxy_tunnel(&mut self, opt: bool); fn match_wildcard(&mut self, opt: bool); diff --git a/src/request/curl.rs b/src/request/curl.rs index 8f42433..7a938a3 100644 --- a/src/request/curl.rs +++ b/src/request/curl.rs @@ -597,11 +597,10 @@ impl<'a> CurlOpts for Curl<'a> { self.curl.follow_location(opt).unwrap(); } - fn add_cookie(&mut self, cookie: String) { - // we are removing it - let flag = CurlFlag::Cookie(CurlFlagType::Cookie.get_value(), Some(cookie.clone())); + fn add_cookie(&mut self, cookie: &str) { + let flag = CurlFlag::Cookie(CurlFlagType::Cookie.get_value(), Some(String::from(cookie))); self.toggle_flag(&flag); - self.curl.cookie(cookie.as_str()).unwrap(); + self.curl.cookie(cookie).unwrap(); } fn set_upload_file(&mut self, file: &str) { @@ -658,9 +657,7 @@ impl<'a> Curl<'a> { fn has_flag(&self, flag: &CurlFlag<'a>) -> bool { self.opts .iter() - .filter(|has| std::mem::discriminant(*has) == std::mem::discriminant(flag)) - .count() - > 0 + .any(|has| std::mem::discriminant(has) == std::mem::discriminant(flag)) } // This is a hack because when we deseialize json from the DB, we get a curl struct with no curl::Easy @@ -691,7 +688,7 @@ impl<'a> Curl<'a> { } CurlFlag::Cookie(..) => { if let Some(val) = opt.get_arg() { - self.add_cookie(val); + self.add_cookie(&val); } } CurlFlag::MatchWildcard(..) => { diff --git a/src/screens/input/request_body_input.rs b/src/screens/input/request_body_input.rs index 0321b37..33ee781 100644 --- a/src/screens/input/request_body_input.rs +++ b/src/screens/input/request_body_input.rs @@ -1,7 +1,7 @@ use crate::app::{App, InputMode}; use crate::display::inputopt::InputOpt; use crate::display::AppOptions; -use crate::screens::{default_rect, small_alert_box}; +use crate::screens::{default_rect, small_alert_box, Screen}; use tui::text::{Line, Text}; use tui::widgets::{Block, Borders, Paragraph}; use tui::{ @@ -77,8 +77,7 @@ pub fn handle_req_body_input_screen( } // we have input (the user has typed something and pressed Enter while in insert mode) if !app.messages.is_empty() { - app.add_app_option(AppOptions::RequestBody( - app.messages.iter().map(|x| x.to_string()).collect(), - )); + app.add_app_option(AppOptions::RequestBody(app.messages[0].clone())); + app.goto_screen(Screen::RequestMenu(String::new())); } }