curl_text_with_args

Function curl_text_with_args 

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

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

Inputs:

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

Output:

  • Ok(String) with response body; 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
  • Returns Err with message containing “429” when HTTP 429 (Too Many Requests) is received

Details:

  • Executes curl with appropriate flags plus extra arguments.
  • On Windows, uses -k flag to skip SSL certificate verification.
  • Uses -i flag to include headers for Retry-After parsing.
  • Uses -w "\n%{http_code}\n" to detect HTTP status codes, especially 429.
  • Provides user-friendly error messages for common curl failure cases.
  • HTTP 429/503 errors include Retry-After information when available.