diff options
Diffstat (limited to 'src/executor.rs')
-rw-r--r-- | src/executor.rs | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/executor.rs b/src/executor.rs index bd9767b..f78fd2a 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -57,7 +57,14 @@ impl Executor { Executor { context } } - fn make_req(&self, bfile: &BarbFile, print_headers: bool) -> ureq::Request { + fn make_req(&self, bfile: &BarbFile, print_req: bool, print_headers: bool) -> ureq::Request { + if print_req { + println!( + "{} {}", + bfile.method_as_string().as_str(), + self.context.substitute(&bfile.url()).as_str() + ); + } let mut req = ureq::request( bfile.method_as_string().as_str(), self.context.substitute(&bfile.url()).as_str(), @@ -91,12 +98,17 @@ impl Executor { match resp { Ok(resp) => Ok(resp), Err(UreqError::Status(_, resp)) => Ok(resp), - Err(UreqError::Transport(transp)) => Err(String::from(transp.to_string())) + Err(UreqError::Transport(transp)) => Err(String::from(transp.to_string())), } } - pub fn execute(&mut self, bfile: &BarbFile, print_headers: bool) -> Result<ureq::Response, String> { - self.run(bfile, self.make_req(&bfile, print_headers)) + pub fn execute( + &mut self, + bfile: &BarbFile, + print_req: bool, + print_headers: bool, + ) -> Result<ureq::Response, String> { + self.run(bfile, self.make_req(&bfile, print_req, print_headers)) } } @@ -142,12 +154,13 @@ mod tests { #[test] fn test_make_req_simple_headers() { let executor = Executor::new(Context::empty()); - let bfile = BarbFile::from_str( - "#GET^http://foo.bar\n#Foo: Bar\n#Bar: Baz\n\n" - ).unwrap(); + let bfile = BarbFile::from_str("#GET^http://foo.bar\n#Foo: Bar\n#Bar: Baz\n\n").unwrap(); let req = executor.make_req(&bfile, false); - assert_eq!(req.header_names(), vec![String::from("foo"), String::from("bar")]); + assert_eq!( + req.header_names(), + vec![String::from("foo"), String::from("bar")] + ); assert_eq!(req.header("foo"), Some("Bar")); assert_eq!(req.header("bar"), Some("Baz")); } |