diff options
Diffstat (limited to 'src/executor.rs')
-rw-r--r-- | src/executor.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/executor.rs b/src/executor.rs index ee17bbf..d9bfaee 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -1,4 +1,4 @@ -use crate::barbfile::BarbFile; +use crate::barbfile::{BarbFile, Header}; use std::collections::HashMap; use std::env; @@ -18,6 +18,7 @@ impl Context { } } + // Preserved for future reference // pub fn get_var(&self, name: String) -> Option<String> { // self.vars // .get(&name) @@ -49,13 +50,18 @@ impl Executor { context: Context::new() } } - + pub fn execute(&mut self, bfile: BarbFile) -> Result<ureq::Response, String> { - let req = ureq::request( + let mut req = ureq::request( bfile.method_as_string().as_str(), self.context.substitute(&bfile.url()).as_str() ); + for header in bfile.headers() { + req = req.set(header.name(), self.context.substitute(header.value()).as_str()); + println!("{} {}", header.name(), self.context.substitute(header.value())); + } + match bfile.method().takes_body() { true => match bfile.body() { Some(body) => req.send_string(body.as_str()), @@ -66,3 +72,5 @@ impl Executor { .map_err(|_| String::from("Error")) } } + +// TODO: tests |