Skip to content

Commit

Permalink
portfetch.tcl: Add option fetch.user_agent.
Browse files Browse the repository at this point in the history
When MacPorts attempts to fetch from DropBox, it gets HTML instead
of the requested file. This is because MacPorts sets libcurl's User-Agent
header in curl.c to "MacPorts/MP_VERSION libcurl/LC_VERSION", which DropBox
responds to as a web brower. The problem was first reported in
https://trac.macports.org/ticket/53942 with regard to port
audio/generaluser-soundfont.

This PR adds an option `fetch.user_agent' which can be set in Portfile
as needed. For example, in audio/generaluser-soundfont/Portfile, adding:

  fetch.user_agent    curl/MacPorts/4.xx

allows fetch to work without a custom fetch block.  If `fetch.user_agent'
is not set, UserAgent as defined in curl.c is used instead.

In the particular case of DropBox, setting the User-Agent header to
"libcurl/..."  doesn't work as one might hope, otherwise swapping the
order of values in curl.c UserAgent variable would be suggested as an
alternative.
  • Loading branch information
slewsys authored and neverpanic committed Jun 8, 2018
1 parent 1877376 commit e5a420c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/port1.0/portfetch.tcl
Expand Up @@ -49,7 +49,7 @@ namespace eval portfetch {
options master_sites patch_sites extract.suffix distfiles patchfiles use_tar \
use_bzip2 use_lzma use_xz use_zip use_7z use_lzip use_dmg dist_subdir \
fetch.type fetch.user fetch.password fetch.use_epsv fetch.ignore_sslcert \
master_sites.mirror_subdir patch_sites.mirror_subdir \
fetch.user_agent master_sites.mirror_subdir patch_sites.mirror_subdir \
bzr.url bzr.revision \
cvs.module cvs.root cvs.password cvs.date cvs.tag cvs.method \
svn.url svn.revision svn.method \
Expand Down Expand Up @@ -115,6 +115,7 @@ default fetch.use_epsv "yes"
default fetch.ignore_sslcert "no"
# Use remote timestamps
default fetch.remote_time "no"
default fetch.user_agent ""

default global_mirror_site "macports_distfiles"
default mirror_sites.listfile {"mirror_sites.tcl"}
Expand Down Expand Up @@ -510,7 +511,7 @@ proc portfetch::hgfetch {args} {
proc portfetch::fetchfiles {args} {
global distpath all_dist_files UI_PREFIX \
fetch.user fetch.password fetch.use_epsv fetch.ignore_sslcert fetch.remote_time \
portverbose
fetch.user_agent portverbose
variable fetch_urls
variable urlmap

Expand All @@ -528,6 +529,10 @@ proc portfetch::fetchfiles {args} {
if {${fetch.remote_time} ne "no"} {
lappend fetch_options "--remote-time"
}
if {${fetch.user_agent} ne ""} {
lappend fetch_options "--user-agent"
lappend fetch_options "${fetch.user_agent}"
}
if {$portverbose eq "yes"} {
lappend fetch_options "--progress"
lappend fetch_options "builtin"
Expand Down

0 comments on commit e5a420c

Please sign in to comment.