Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #133 from PThorpe92/refactor
Browse files Browse the repository at this point in the history
fix duplicate request bodies
  • Loading branch information
PThorpe92 authored Apr 29, 2024
2 parents 593d8ae + ad1195e commit 150f850
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl<'a> Default for App<'a> {
}

impl<'a> App<'a> {
#[allow(dead_code)]
fn new_test_db() -> Self {
Self {
db: Box::new(DB::new_test().expect("Failed to create database")),
Expand Down Expand Up @@ -351,14 +352,17 @@ impl<'a> App<'a> {

// Takes an array index of the selected item
pub fn execute_saved_command(&mut self, json: &str) {
let mut command: Curl = serde_json::from_str(json)
.map_err(|e| e.to_string())
.unwrap();
command.easy_from_opts();
match command.execute(None) {
Ok(_) => self.set_response(&command.get_response().unwrap_or("".to_string())),
let command: Result<Curl, String> = serde_json::from_str(json).map_err(|e| e.to_string());
match command {
Ok(mut cmd) => {
cmd.easy_from_opts();
match cmd.execute(None) {
Ok(_) => self.set_response(&cmd.get_response().unwrap_or("".to_string())),
Err(e) => self.set_response(&e),
};
}
Err(e) => self.set_response(&e),
};
}
}

pub fn copy_to_clipboard(&self, opt: &str) -> Result<(), String> {
Expand Down
3 changes: 3 additions & 0 deletions src/request/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ impl Curl {
if self.ser {
self.opts.push(AppOptions::RequestBody(body.to_string()));
}
if self.opts.iter().any(|x| std::mem::discriminant(x) == std::mem::discriminant(&AppOptions::RequestBody(body.to_string()))) {
self.opts.retain(|x| std::mem::discriminant(x) != std::mem::discriminant(&AppOptions::RequestBody(body.to_string())));
}
self.opts.push(AppOptions::RequestBody(body.to_string()));
self.curl
.post_fields_copy(body.as_bytes())
Expand Down

0 comments on commit 150f850

Please sign in to comment.