Skip to content

Commit

Permalink
change the default HTTP user agent when libcurl is used
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@76204 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Mar 6, 2019
1 parent 81cf838 commit def075d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions doc/NEWS.Rd
Expand Up @@ -302,6 +302,11 @@
\item \code{stopifnot()} has been simplified thanks to Suharto
Anggono's proposals to become considerably faster for cheap
expressions.
\item The default \sQuote{user agent} has been changed when
accessing \samp{http://} and \samp{https://} sites using
\samp{libcurl}. (A site was found which caused \samp{libcurl} to
infinite-loop with the previous default.)
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/library/base/man/options.Rd
@@ -1,6 +1,6 @@
% File src/library/base/man/options.Rd
% Part of the R package, https://www.R-project.org
% Copyright 1995-2018 R Core Team
% Copyright 1995-2019 R Core Team
% Distributed under GPL 2 or later

\name{options}
Expand Down Expand Up @@ -632,10 +632,13 @@ getOption(x, default = NULL)
\item{\code{help_type}:}{default for an argument of
\code{\link{help}}, used also as the help type by \code{\link{?}}.}
\item{\code{HTTPUserAgent}:}{string used as the user agent in HTTP(S)
requests. If \code{NULL}, requests will be made without a
user agent header.
The default is \code{R (<version> <platform> <arch> <os>)} .}
\item{\code{HTTPUserAgent}:}{string used as the \sQuote{user agent} in
HTTP(S) requests by \code{\link{download.file}}, \code{\link{url}}
and \code{\link{curlGetHeaders}}, or \code{NULL} when requests will
be made without a user agent header. The default is
\code{R (<version> <platform> <arch> <os>)}
except when \samp{libcurl} is used when it is
\code{libcurl/7.<xx>.<y>} for the \samp{libcurl} version in use.}
\item{\code{install.lock}:}{logical: should per-directory package
locking be used by \code{\link{install.packages}}? Most useful
Expand Down
19 changes: 19 additions & 0 deletions src/modules/internet/libcurl.c
Expand Up @@ -236,6 +236,7 @@ static void curlCommon(CURL *hnd, int redirect, int verify)
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
}
#if 0
// for consistency, but all utils:::makeUserAgent does is look up an option.
SEXP sMakeUserAgent = install("makeUserAgent");
SEXP agentFun = PROTECT(lang2(sMakeUserAgent, ScalarLogical(0)));
Expand All @@ -246,6 +247,24 @@ static void curlCommon(CURL *hnd, int redirect, int verify)
if(TYPEOF(sua) != NILSXP)
curl_easy_setopt(hnd, CURLOPT_USERAGENT, CHAR(STRING_ELT(sua, 0)));
UNPROTECT(2);
#else
int Default = 1;
SEXP sua = GetOption1(install("HTTPUserAgent")); // set in utils startup
if (TYPEOF(sua) == STRSXP && LENGTH(sua) == 1 ) {
const char *p = CHAR(STRING_ELT(sua, 0));
if (p[0] && p[1] && p[2] && p[0] == 'R' && p[1] == ' ' && p[2] == '(') {
} else {
Default = 0;
curl_easy_setopt(hnd, CURLOPT_USERAGENT, p);
}
}
if (Default) {
char buf[20];
curl_version_info_data *d = curl_version_info(CURLVERSION_NOW);
snprintf(buf, 20, "libcurl/%s", d->version);
curl_easy_setopt(hnd, CURLOPT_USERAGENT, buf);
}
#endif
int timeout0 = asInteger(GetOption1(install("timeout")));
long timeout = timeout0 = NA_INTEGER ? 0 : 1000L * timeout0;
curl_easy_setopt(hnd, CURLOPT_CONNECTTIMEOUT_MS, timeout);
Expand Down

0 comments on commit def075d

Please sign in to comment.