Skip to content

Commit

Permalink
Remove cloning on AST request helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Jan 31, 2025
1 parent 0887fcb commit 7f69db6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/hurl_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ fn run_request(
fn get_output_source_info(entry: &Entry) -> SourceInfo {
let mut source_info = entry.source_info();
for option_entry in entry.request.options() {
if let OptionKind::Output(value) = option_entry.kind {
if let OptionKind::Output(value) = &option_entry.kind {
source_info = value.source_info;
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/hurl/src/runner/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn eval_request(

// Query string params
let mut querystring = vec![];
for param in &request.querystring_params() {
for param in request.querystring_params() {
let name = template::eval_template(&param.key, variables)?;
let value = template::eval_template(&param.value, variables)?;
let param = http::Param { name, value };
Expand All @@ -70,7 +70,7 @@ pub fn eval_request(

// Form params
let mut form = vec![];
for param in &request.form_params() {
for param in request.form_params() {
let name = template::eval_template(&param.key, variables)?;
let value = template::eval_template(&param.value, variables)?;
let param = http::Param { name, value };
Expand All @@ -79,7 +79,7 @@ pub fn eval_request(

// Cookies
let mut cookies = vec![];
for cookie in &request.cookies() {
for cookie in request.cookies() {
let name = template::eval_template(&cookie.name, variables)?;
let value = template::eval_template(&cookie.value, variables)?;
let cookie = http::RequestCookie { name, value };
Expand All @@ -92,7 +92,7 @@ pub fn eval_request(
};

let mut multipart = vec![];
for multipart_param in &request.multipart_form_data() {
for multipart_param in request.multipart_form_data() {
let param = multipart::eval_multipart_param(multipart_param, variables, context_dir)?;
multipart.push(param);
}
Expand Down
52 changes: 35 additions & 17 deletions packages/hurl_core/src/ast/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,56 +56,74 @@ pub struct Request {
}

impl Request {
pub fn querystring_params(&self) -> Vec<KeyValue> {
/// Returns the query strings params for this request.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams>.
pub fn querystring_params(&self) -> &[KeyValue] {
for section in &self.sections {
if let SectionValue::QueryParams(params, _) = &section.value {
return params.clone();
return params;
}
}
vec![]
&[]
}
pub fn form_params(&self) -> Vec<KeyValue> {

/// Returns the form params for this request.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST#url-encoded_form_submission>.
pub fn form_params(&self) -> &[KeyValue] {
for section in &self.sections {
if let SectionValue::FormParams(params, _) = &section.value {
return params.clone();
return params;
}
}
vec![]
&[]
}
pub fn multipart_form_data(&self) -> Vec<MultipartParam> {

/// Returns the multipart form data for this request.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST#multipart_form_submission>.
pub fn multipart_form_data(&self) -> &[MultipartParam] {
for section in &self.sections {
if let SectionValue::MultipartFormData(params, _) = &section.value {
return params.clone();
return params;
}
}
vec![]
&[]
}

pub fn cookies(&self) -> Vec<Cookie> {
/// Returns the list of cookies on this request.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie>.
pub fn cookies(&self) -> &[Cookie] {
for section in &self.sections {
if let SectionValue::Cookies(cookies) = &section.value {
return cookies.clone();
return cookies;
}
}
vec![]
&[]
}

pub fn basic_auth(&self) -> Option<KeyValue> {
/// Returns the basic authentication on this request.
///
/// See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication>.
pub fn basic_auth(&self) -> Option<&KeyValue> {
for section in &self.sections {
if let SectionValue::BasicAuth(kv) = &section.value {
return kv.clone();
return kv.as_ref();
}
}
None
}

pub fn options(&self) -> Vec<EntryOption> {
/// Returns the options specific for this request.
pub fn options(&self) -> &[EntryOption] {
for section in &self.sections {
if let SectionValue::Options(options) = &section.value {
return options.clone();
return options;
}
}
vec![]
&[]
}
}

Expand Down

0 comments on commit 7f69db6

Please sign in to comment.