curl_text_with_args_headers

Function curl_text_with_args_headers 

Source
pub fn curl_text_with_args_headers(
    url: &str,
    extra_args: &[&str],
) -> Result<CurlResponse, Box<dyn Error + Send + Sync>>
Expand description

What: Fetch plain text from a URL using curl with custom arguments, including headers.

Inputs:

  • url: URL to request
  • extra_args: Additional curl arguments (e.g., ["--max-time", "10"])

Output:

  • Ok(CurlResponse) with response body, status code, and parsed headers; Err if curl or UTF-8 decoding fails

ยงErrors

  • Returns Err when curl command execution fails (I/O error or curl not found)
  • Returns Err when curl exits with non-zero status (network errors, HTTP errors, timeouts)
  • Returns Err when response body cannot be decoded as UTF-8

Details:

  • Executes curl with -i flag to include headers in output.
  • Uses -w "\n%{http_code}\n" to get HTTP status code at the end.
  • Parses Retry-After header from response headers.
  • Separates headers from body in the response.