From cf8dffba03b8e56603b94f8f1956393ab1d2a7c8 Mon Sep 17 00:00:00 2001 From: jcamiel Date: Tue, 3 Oct 2023 17:01:32 +0200 Subject: [PATCH] Reset libcurl handle at the start of the execute function. Actually, we can exit from the `client::execute` function without reseting the libcurl handle. It seems more cautious to reset the curl handle at the start of the function, prior to set everything. --- packages/hurl/src/http/client.rs | 28 ++++++++++++++------------- packages/hurl/src/runner/hurl_file.rs | 3 +-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/hurl/src/http/client.rs b/packages/hurl/src/http/client.rs index a349e2ae5..ea687ea4e 100644 --- a/packages/hurl/src/http/client.rs +++ b/packages/hurl/src/http/client.rs @@ -50,17 +50,8 @@ pub struct Client { impl Client { /// Creates HTTP Hurl client. - pub fn new(cookie_input_file: Option) -> Client { - let mut h = easy::Easy::new(); - - // Set handle attributes - // that are not affected by reset - - // Activate cookie storage - // with or without persistence (empty string) - h.cookie_file(cookie_input_file.unwrap_or_default()) - .unwrap(); - + pub fn new() -> Client { + let h = easy::Easy::new(); Client { handle: Box::new(h), } @@ -119,7 +110,19 @@ impl Client { options: &ClientOptions, logger: &Logger, ) -> Result { - // Set handle attributes that have not been set or reset. + // The handle can be mutated in this function: to start from a clean state, we reset it + // prior to everything. + self.handle.reset(); + + // Activates cookie engine. + // See + // > It also enables the cookie engine, making libcurl parse and send cookies on subsequent + // > requests with this handle. + // > By passing the empty string ("") to this option, you enable the cookie + // > engine without reading any initial cookies. + self.handle + .cookie_file(options.cookie_input_file.clone().unwrap_or_default()) + .unwrap(); // We force libcurl verbose mode regardless of Hurl verbose option to be able // to capture HTTP request headers in libcurl `debug_function`. That's the only @@ -339,7 +342,6 @@ impl Client { let stop = Utc::now(); let duration = (stop - start).to_std().unwrap(); let timings = Timings::new(&mut self.handle, start, stop); - self.handle.reset(); let request = Request { url: url.clone(), diff --git a/packages/hurl/src/runner/hurl_file.rs b/packages/hurl/src/runner/hurl_file.rs index 66a40a220..b2673e088 100644 --- a/packages/hurl/src/runner/hurl_file.rs +++ b/packages/hurl/src/runner/hurl_file.rs @@ -90,8 +90,7 @@ pub fn run( log_run_info(&hurl_file, runner_options, variables, &logger); // Now, we have a syntactically correct HurlFile instance, we can run it. - let cookie_input_file = runner_options.cookie_input_file.clone(); - let mut http_client = http::Client::new(cookie_input_file); + let mut http_client = http::Client::new(); let mut entries = vec![]; let mut variables = variables.clone(); let mut entry_index = 1;