summaryrefslogtreecommitdiffstats
path: root/extensions/PhabBugz/lib
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-10-11 21:28:18 +0200
committerGitHub <noreply@github.com>2018-10-11 21:28:18 +0200
commit871fc7dd332dadd24a7e6e1db3c7f5e8ef93b00e (patch)
tree659b0d989541d3d68e7709e7516b5e959ccf3884 /extensions/PhabBugz/lib
parent6d375501e97b63a519afc9e46d2d388acc28307f (diff)
downloadbugzilla-871fc7dd332dadd24a7e6e1db3c7f5e8ef93b00e.tar.gz
bugzilla-871fc7dd332dadd24a7e6e1db3c7f5e8ef93b00e.tar.xz
Bug 1498206 - Replace LWP::UserAgent with Mojo::UserAgent in phabbugz extension
Diffstat (limited to 'extensions/PhabBugz/lib')
-rw-r--r--extensions/PhabBugz/lib/Util.pm32
1 files changed, 11 insertions, 21 deletions
diff --git a/extensions/PhabBugz/lib/Util.pm b/extensions/PhabBugz/lib/Util.pm
index f2876366f..67b29f27c 100644
--- a/extensions/PhabBugz/lib/Util.pm
+++ b/extensions/PhabBugz/lib/Util.pm
@@ -20,14 +20,14 @@ use Bugzilla::Util qw(trim);
use Bugzilla::Extension::PhabBugz::Constants;
use Bugzilla::Extension::PhabBugz::Types qw(:types);
-use JSON::XS qw(encode_json decode_json);
use List::Util qw(first);
-use LWP::UserAgent;
use Taint::Util qw(untaint);
use Try::Tiny;
use Type::Params qw( compile );
use Type::Utils;
use Types::Standard qw( :types );
+use Mojo::UserAgent;
+use Mojo::JSON qw(encode_json);
use base qw(Exporter);
@@ -159,11 +159,10 @@ sub request {
my $ua = $request_cache->{phabricator_ua};
unless ($ua) {
- $ua = $request_cache->{phabricator_ua} = LWP::UserAgent->new(timeout => 10);
+ $ua = $request_cache->{phabricator_ua} = Mojo::UserAgent->new;
if ($params->{proxy_url}) {
- $ua->proxy('https', $params->{proxy_url});
+ $ua->proxy($params->{proxy_url});
}
- $ua->default_header('Content-Type' => 'application/x-www-form-urlencoded');
}
my $phab_api_key = $params->{phabricator_api_key};
@@ -175,25 +174,16 @@ sub request {
$data->{__conduit__} = { token => $phab_api_key };
- my $response = $ua->post($full_uri, { params => encode_json($data) });
-
+ my $response = $ua->post($full_uri => form => { params => encode_json($data) })->result;
ThrowCodeError('phabricator_api_error', { reason => $response->message })
if $response->is_error;
- my $result;
- my $result_ok = eval {
- my $content = $response->content;
- untaint($content);
- $result = decode_json( $content );
- 1;
- };
- if (!$result_ok || $result->{error_code}) {
- ThrowCodeError('phabricator_api_error',
- { reason => 'JSON decode failure' }) if !$result_ok;
- ThrowCodeError('phabricator_api_error',
- { code => $result->{error_code},
- reason => $result->{error_info} }) if $result->{error_code};
- }
+ my $result = $response->json;
+ ThrowCodeError('phabricator_api_error',
+ { reason => 'JSON decode failure' }) if !defined($result);
+ ThrowCodeError('phabricator_api_error',
+ { code => $result->{error_code},
+ reason => $result->{error_info} }) if $result->{error_code};
return $result;
}