Repository: Orange-OpenSource/hurl
File: packages/hurl/src/runner/query.rs (Rust)

Code before:
        QueryValue::Variable { name, .. } => eval_query_variable(name, variables),
        QueryValue::Duration => eval_query_duration(response),
        QueryValue::Bytes => eval_query_bytes(response, query.source_info),
        QueryValue::Sha256 => eval_query_sha256(response, query.source_info),
        QueryValue::Md5 => eval_query_md5(response, query.source_info),
        QueryValue::Certificate {
            attribute_name: field,
            ..
        } => eval_query_certificate(response, *field),
    }
}

/// Evaluates the response status code using the HTTP `response`.
fn eval_query_status(response: &http::Response) -> QueryResult {
    Ok(Some(Value::Number(Number::Integer(i64::from(
        response.status,
    )))))
}

/// Evaluates the version on the HTTP `response`
fn eval_query_version(response: &http::Response) -> QueryResult {
    Ok(Some(Value::String(
        response
            .version
            .to_string()
            .split("/")
            .last()
            .unwrap()
            .to_string(),
    )))
}

/// Evaluates the final URL of the HTTP `response`.
fn eval_query_url(response: &http::Response) -> QueryResult {
    Ok(Some(Value::String(response.url.to_string())))
}

/// Evaluates a response query header `name`, on the HTTP `response` given a set of `variables`.
fn eval_query_header(
    response: &http::Response,
    name: &Template,
    variables: &VariableSet,
) -> QueryResult {
    let name = eval_template(name, variables)?;
    let values = response.headers.values(&name);
    if values.is_empty() {
        Ok(None)
    } else if values.len() == 1 {
        let value = values.first().unwrap().to_string();
        Ok(Some(Value::String(value)))
    } else {

Review comment (suggestion):
Maybe instead of splitting, we can remove prefix `HTTP/` [strip_prefix](https://doc.rust-lang.org/std/primitive.str.html#method.strip_prefix)

Code after:
        QueryValue::Variable { name, .. } => eval_query_variable(name, variables),
        QueryValue::Duration => eval_query_duration(response),
        QueryValue::Bytes => eval_query_bytes(response, query.source_info),
        QueryValue::Sha256 => eval_query_sha256(response, query.source_info),
        QueryValue::Md5 => eval_query_md5(response, query.source_info),
        QueryValue::Certificate {
            attribute_name: field,
            ..
        } => eval_query_certificate(response, *field),
        QueryValue::Ip => eval_ip(response),
    }
}

/// Evaluates the response status code using the HTTP `response`.
fn eval_query_status(response: &http::Response) -> QueryResult {
    Ok(Some(Value::Number(Number::Integer(i64::from(
        response.status,
    )))))
}

/// Evaluates the version on the HTTP `response`
fn eval_query_version(response: &http::Response) -> QueryResult {
    Ok(Some(Value::String(
        response
            .version
            .to_string()
            .strip_prefix("HTTP/")
            .unwrap()
            .to_string(),
    )))
}

/// Evaluates the final URL of the HTTP `response`.
fn eval_query_url(response: &http::Response) -> QueryResult {
    Ok(Some(Value::String(response.url.to_string())))
}

/// Evaluates a response query header `name`, on the HTTP `response` given a set of `variables`.
fn eval_query_header(
    response: &http::Response,
    name: &Template,
    variables: &VariableSet,
) -> QueryResult {
    let name = eval_template(name, variables)?;
    let values = response.headers.values(&name);
    if values.is_empty() {
        Ok(None)
    } else if values.len() == 1 {
        let value = values.first().unwrap().to_string();
        Ok(Some(Value::String(value)))
    } else {