mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-26 00:22:10 +03:00
Simplify execute HTTP client method.
This commit is contained in:
parent
a6fddfe13f
commit
21920dd78e
@ -83,37 +83,33 @@ impl Client {
|
|||||||
let mut redirect_count = 0;
|
let mut redirect_count = 0;
|
||||||
loop {
|
loop {
|
||||||
let (request, response) = self.execute(&request_spec, options, logger)?;
|
let (request, response) = self.execute(&request_spec, options, logger)?;
|
||||||
calls.push((request.clone(), response.clone()));
|
|
||||||
if !options.follow_location {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
let base_url = request.base_url()?;
|
let base_url = request.base_url()?;
|
||||||
if let Some(url) = self.get_follow_location(&response, &base_url) {
|
let redirect_url = self.get_follow_location(&response, &base_url);
|
||||||
logger.debug("");
|
calls.push((request, response));
|
||||||
logger.debug(format!("=> Redirect to {url}").as_str());
|
if !options.follow_location || redirect_url.is_none() {
|
||||||
logger.debug("");
|
|
||||||
request_spec = RequestSpec {
|
|
||||||
method: Method::Get,
|
|
||||||
url,
|
|
||||||
headers: vec![],
|
|
||||||
querystring: vec![],
|
|
||||||
form: vec![],
|
|
||||||
multipart: vec![],
|
|
||||||
cookies: vec![],
|
|
||||||
body: Body::Binary(vec![]),
|
|
||||||
content_type: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
redirect_count += 1;
|
|
||||||
if let Some(max_redirect) = options.max_redirect {
|
|
||||||
if redirect_count > max_redirect {
|
|
||||||
return Err(HttpError::TooManyRedirect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
let redirect_url = redirect_url.unwrap();
|
||||||
|
logger.debug("");
|
||||||
|
logger.debug(format!("=> Redirect to {redirect_url}").as_str());
|
||||||
|
logger.debug("");
|
||||||
|
redirect_count += 1;
|
||||||
|
if let Some(max_redirect) = options.max_redirect {
|
||||||
|
if redirect_count > max_redirect {
|
||||||
|
return Err(HttpError::TooManyRedirect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request_spec = RequestSpec {
|
||||||
|
method: Method::Get,
|
||||||
|
url: redirect_url,
|
||||||
|
headers: vec![],
|
||||||
|
querystring: vec![],
|
||||||
|
form: vec![],
|
||||||
|
multipart: vec![],
|
||||||
|
cookies: vec![],
|
||||||
|
body: Body::Binary(vec![]),
|
||||||
|
content_type: None,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Ok(calls)
|
Ok(calls)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user