App-MonM

 view release on metacpan or  search on metacpan

lib/App/MonM/Checkit/HTTP.pm  view on Meta::CPAN


=cut

use vars qw/$VERSION/;
$VERSION = '1.01';

use Encode;
use CTK::ConfGenUtil;
use URI;
use LWP::UserAgent();
use HTTP::Request();

use App::MonM::Const qw/PROJECTNAME/;
use App::MonM::Util qw/set2attr getTimeOffset/;

use constant {
        DEFAULT_URL     => "http://localhost",
        DEFAULT_METHOD  => "GET",
        DEFAULT_TIMEOUT => 180,
    };

lib/App/MonM/Checkit/HTTP.pm  view on Meta::CPAN

        agent               => sprintf("%s/%s", PROJECTNAME, $VERSION),
        timeout             => $timeout,
        protocols_allowed   => ['http', 'https'],
    );
    $ua->default_header($_, value($attr, $_)) for (keys %$attr);

    # Proxy
    $ua->proxy(['http', 'https'], $proxy) if $proxy;

    # Prepare request data
    my $request = HTTP::Request->new(uc($method) => $uri);
    if ($method =~ /PUT|POST|PATCH/) {
        Encode::_utf8_on($content);
        $request->header('Content-Length' => length(Encode::encode("utf8", $content)));
        $request->content(Encode::encode("utf8", $content));
    }

    # Request
    my $response = $ua->request($request);

    # Result



( run in 0.276 second using v1.01-cache-2.11-cpan-de7293f3b23 )