diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2024-06-06 04:42:33 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2024-06-06 04:44:24 -0500 |
commit | 2f9a16cfc33b0397f796fea70be1f92dd8c58b32 (patch) | |
tree | 41bba1a6887dfd99094a8aefc1efa6c4e738bab0 | |
parent | 58789a2e84042875cb1556fbb430a5af5e370e86 (diff) | |
download | abuild-2f9a16cfc33b0397f796fea70be1f92dd8c58b32.tar.gz abuild-2f9a16cfc33b0397f796fea70be1f92dd8c58b32.tar.bz2 abuild-2f9a16cfc33b0397f796fea70be1f92dd8c58b32.tar.xz abuild-2f9a16cfc33b0397f796fea70be1f92dd8c58b32.zip |
abuild-fetch: Use User-Agent properly
* Use ABUILD_USER_AGENT environment variable, if present, to customise.
* Default to abuild/VERSION, meeting HTTP spec and preventing us from
being blocked as a bot by silly upstreams that don't like curl.
Closes: #7
-rw-r--r-- | abuild-fetch.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/abuild-fetch.c b/abuild-fetch.c index 7145d7e..5adb5fc 100644 --- a/abuild-fetch.c +++ b/abuild-fetch.c @@ -81,7 +81,8 @@ int fetch(char *url, const char *destdir) { int lockfd, status=0; char outfile[PATH_MAX], partfile[PATH_MAX]; - char *name, *p; + char agent[50]; + char *name, *p, *env; struct flock fl = { .l_type = F_WRLCK, .l_whence = SEEK_SET, @@ -140,6 +141,18 @@ int fetch(char *url, const char *destdir) add_opt(&wgetcmd, "-c"); } + add_opt(&curlcmd, "-A"); + add_opt(&wgetcmd, "-U"); + env = getenv("ABUILD_USER_AGENT"); + if (env != NULL) { + add_opt(&curlcmd, env); + add_opt(&wgetcmd, env); + } else { + snprintf(agent, sizeof(agent), "abuild/%s", VERSTR); + add_opt(&curlcmd, agent); + add_opt(&wgetcmd, agent); + } + add_opt(&curlcmd, url); add_opt(&wgetcmd, url); |