summaryrefslogtreecommitdiff
path: root/lib/RHRD/utils.pm
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-05-25 14:58:10 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-05-25 14:58:10 (GMT)
commit1422d23f242b515e7b2751f35db1571eca635bfe (patch)
tree756cec1b96b9b9e262fa747e2aaa87e74406c90b /lib/RHRD/utils.pm
parentfc63aa732e54d8ed072a9f939de43efdcd855fc6 (diff)
allow additional headers to be used when fetching json
Diffstat (limited to 'lib/RHRD/utils.pm')
-rwxr-xr-xlib/RHRD/utils.pm8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm
index 13e8ca1..f3a76bf 100755
--- a/lib/RHRD/utils.pm
+++ b/lib/RHRD/utils.pm
@@ -161,7 +161,7 @@ sub cmdline_dow
sub fetch_parse_json
{
- my ($url, $ua_str) = @_;
+ my ($url, $ua_str, $headers) = @_;
my $uri = URI->new($url);
$ua_str = "Radio Helsinki Rivendell Utilities" unless $ua_str;
@@ -169,6 +169,12 @@ sub fetch_parse_json
my $ua = LWP::UserAgent->new;
$ua->agent($ua_str);
$ua->env_proxy;
+ if (defined $headers) {
+ while(my ($field, $value) = each %{$headers}) {
+ $ua->default_header($field, $value);
+ }
+ }
+
my $res = URI::Fetch->fetch($uri, UserAgent => $ua)
or return (0, URI::Fetch->errstr);
if($res->status == URI::Fetch::URI_GONE()) {