pub fn curl_args(url: &str, extra_args: &[&str]) -> Vec<String>Expand description
Build curl command arguments for fetching a URL.
On Windows, adds -k flag to skip SSL certificate verification to work around
common SSL certificate issues (exit code 77). On other platforms, uses standard
SSL verification.
Inputs:
url: The URL to fetchextra_args: Additional curl arguments (e.g.,["--max-time", "10"])
Output:
- Vector of curl arguments ready to pass to
Command::args()
Details:
- Base arguments:
-sSLf(silent, show errors, follow redirects, fail on HTTP errors) - Windows: Adds
-kto skip SSL verification - Adds User-Agent header to avoid being blocked by APIs
- Appends
extra_argsandurlat the end
ยงExamples
use pacsea::util::curl_args;
// Building arguments to fetch package info from the AUR RPC API
let aur_args = curl_args("https://aur.archlinux.org/rpc/?v=5&type=info&arg=linux-zen", &["--max-time", "10"]);
// On Windows, includes -k flag; always includes -sSLf and User-Agent
assert!(aur_args.contains(&"-sSLf".to_string()));
assert!(aur_args.contains(&"-H".to_string()));
// User-Agent is browser-like (Firefox) with Pacsea identifier
let user_agent = aur_args.iter().find(|arg| arg.contains("Mozilla") && arg.contains("Pacsea/")).unwrap();
assert!(user_agent.contains("Mozilla/5.0"));
assert!(user_agent.contains("Firefox"));
assert!(user_agent.contains("Pacsea/"));
assert!(aur_args.contains(&"--max-time".to_string()));
assert!(aur_args.contains(&"10".to_string()));
assert!(aur_args.last().unwrap().starts_with("https://aur.archlinux.org"));
// Building arguments to fetch the core repository database
let repo_args = curl_args("https://archlinux.org/packages/core/x86_64/pacman/", &["--compressed"]);
assert!(repo_args.contains(&"--compressed".to_string()));
assert!(repo_args.last().unwrap().contains("archlinux.org"));
// Building arguments with no extra options
let simple_args = curl_args("https://example.com/feed", &[]);
assert_eq!(simple_args.last().unwrap(), "https://example.com/feed");