mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-09-21 18:57:33 +03:00
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.
This commit is contained in:
parent
411f0ed8f5
commit
cf8dffba03
@ -50,17 +50,8 @@ pub struct Client {
|
||||
|
||||
impl Client {
|
||||
/// Creates HTTP Hurl client.
|
||||
pub fn new(cookie_input_file: Option<String>) -> 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<Call, HttpError> {
|
||||
// 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 <https://curl.se/libcurl/c/CURLOPT_COOKIEFILE.html>
|
||||
// > 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(),
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user