REST-Client-281/0000755000175000017500000000000014157202615013270 5ustar huettelhuettelREST-Client-281/lib/0000755000175000017500000000000014157202615014036 5ustar huettelhuettelREST-Client-281/lib/REST/0000755000175000017500000000000014157202615014613 5ustar huettelhuettelREST-Client-281/lib/REST/Client.pm0000644000175000017500000003116614157202615016376 0ustar huettelhuettelpackage REST::Client; #ABSTRACT: A simple client for interacting with RESTful http/https resources our $VERSION = '281'; use strict; use warnings; use 5.008_000; use constant TRUE => 1; use constant FALSE => 0; use URI; use LWP::UserAgent; use Carp qw(croak carp); sub new { my $class = shift; my $config; $class->_buildAccessors(); if(ref $_[0] eq 'HASH'){ $config = shift; }elsif(scalar @_ && scalar @_ % 2 == 0){ $config = {@_}; }else{ $config = {}; } my $self = bless({}, $class); $self->{'_config'} = $config; $self->_buildUseragent(); return $self; } sub addHeader { my $self = shift; my $header = shift; my $value = shift; my $headers = $self->{'_headers'} || {}; $headers->{$header} = $value; $self->{'_headers'} = $headers; return; } sub buildQuery { my $self = shift; my $uri = URI->new(); $uri->query_form(@_); return $uri->as_string(); } sub GET { my $self = shift; my $url = shift; my $headers = shift; return $self->request('GET', $url, undef, $headers); } sub PUT { my $self = shift; return $self->request('PUT', @_); } sub PATCH { my $self = shift; return $self->request('PATCH', @_); } sub POST { my $self = shift; return $self->request('POST', @_); } sub DELETE { my $self = shift; my $url = shift; my $headers = shift; return $self->request('DELETE', $url, undef, $headers); } sub OPTIONS { my $self = shift; my $url = shift; my $headers = shift; return $self->request('OPTIONS', $url, undef, $headers); } sub HEAD { my $self = shift; my $url = shift; my $headers = shift; return $self->request('HEAD', $url, undef, $headers); } sub request { my $self = shift; my $method = shift; my $url = shift; my $content = shift; my $headers = shift; $self->{'_res'} = undef; $self->_buildUseragent(); #error check croak "REST::Client exception: Must provide a url to $method" unless $url; croak "REST::Client exception: headers must be presented as a hashref" if $headers && ref $headers ne 'HASH'; $url = $self->_prepareURL($url); my $ua = $self->getUseragent(); if(defined $self->getTimeout()){ $ua->timeout($self->getTimeout); }else{ $ua->timeout(300); } my $req = HTTP::Request->new( $method => $url ); #build headers if(defined $content && length($content)){ $req->content($content); $req->header('Content-Length', length($content)); }else{ $req->header('Content-Length', 0); } my $custom_headers = $self->{'_headers'} || {}; for my $header (keys %$custom_headers){ $req->header($header, $custom_headers->{$header}); } for my $header (keys %$headers){ $req->header($header, $headers->{$header}); } #prime LWP with ssl certfile if we have values if($self->getCert){ carp "REST::Client exception: Certs defined but not using https" unless $url =~ /^https/; croak "REST::Client exception: Cannot read cert and key file" unless -f $self->getCert && -f $self->getKey; $ua->ssl_opts(SSL_cert_file => $self->getCert); $ua->ssl_opts(SSL_key_file => $self->getKey); } #prime LWP with CA file if we have one if(my $ca = $self->getCa){ croak "REST::Client exception: Cannot read CA file" unless -f $ca; $ua->ssl_opts(SSL_ca_file => $ca); } #prime LWP with PKCS12 certificate if we have one if($self->getPkcs12){ carp "REST::Client exception: PKCS12 cert defined but not using https" unless $url =~ /^https/; croak "REST::Client exception: Cannot read PKCS12 cert" unless -f $self->getPkcs12; $ENV{HTTPS_PKCS12_FILE} = $self->getPkcs12; if($self->getPkcs12password){ $ENV{HTTPS_PKCS12_PASSWORD} = $self->getPkcs12password; } } my $res = $self->getFollow ? $ua->request( $req, $self->getContentFile ) : $ua->simple_request( $req, $self->getContentFile ); $self->{_res} = $res; return $self; } sub responseCode { my $self = shift; return $self->{_res}->code; } sub responseContent { my $self = shift; return $self->{_res}->content; } sub responseHeaders { my $self = shift; return $self->{_res}->headers()->header_field_names(); } sub responseHeader { my $self = shift; my $header = shift; croak "REST::Client exception: no header provided to responseHeader" unless $header; return $self->{_res}->header($header); } sub responseXpath { my $self = shift; require XML::LibXML; my $xml= XML::LibXML->new(); $xml->load_ext_dtd(0); if($self->responseHeader('Content-type') =~ /html/){ return XML::LibXML::XPathContext->new($xml->parse_html_string( $self->responseContent() )); }else{ return XML::LibXML::XPathContext->new($xml->parse_string( $self->responseContent() )); } } # Private methods sub _prepareURL { my $self = shift; my $url = shift; # Do not prepend default host to absolute URLs. return $url if $url =~ /^https?:/; my $host = $self->getHost; if($host){ $url = '/'.$url unless $url =~ /^\//; $url = $host . $url; } unless($url =~ /^\w+:\/\//){ $url = ($self->getCert ? 'https://' : 'http://') . $url; } return $url; } sub _buildUseragent { my $self = shift; return if $self->getUseragent(); my $ua = LWP::UserAgent->new; $ua->agent("REST::Client/$VERSION"); $self->setUseragent($ua); return; } sub _buildAccessors { my $self = shift; return if $self->can('setHost'); my @attributes = qw(Host Key Cert Ca Timeout Follow Useragent Pkcs12 Pkcs12password ContentFile); for my $attribute (@attributes){ my $set_method = " sub { my \$self = shift; \$self->{'_config'}{lc('$attribute')} = shift; return \$self->{'_config'}{lc('$attribute')}; }"; my $get_method = " sub { my \$self = shift; return \$self->{'_config'}{lc('$attribute')}; }"; { no strict 'refs'; *{'REST::Client::set'.$attribute} = eval $set_method ; *{'REST::Client::get'.$attribute} = eval $get_method ; } } return; } 1; __END__ =pod =encoding UTF-8 =head1 NAME REST::Client - A simple client for interacting with RESTful http/https resources =head1 VERSION version 281 =head1 SYNOPSIS use REST::Client; #The basic use case my $client = REST::Client->new(); $client->GET('http://example.com/dir/file.xml'); print $client->responseContent(); #A host can be set for convienience $client->setHost('http://example.com'); $client->PUT('/dir/file.xml', 'new content'); if( $client->responseCode() eq '200' ){ print "Updated\n"; } #custom request headers may be added $client->addHeader('CustomHeader', 'Value'); #response headers may be gathered print $client->responseHeader('ResponseHeader'); #X509 client authentication $client->setCert('/path/to/ssl.crt'); $client->setKey('/path/to/ssl.key'); #add a CA to verify server certificates $client->setCa('/path/to/ca.file'); #you may set a timeout on requests, in seconds $client->setTimeout(10); #options may be passed as well as set $client = REST::Client->new({ host => 'https://example.com', cert => '/path/to/ssl.crt', key => '/path/to/ssl.key', ca => '/path/to/ca.file', timeout => 10, }); $client->GET('/dir/file', {CustomHeader => 'Value'}); # Requests can be specificed directly as well $client->request('GET', '/dir/file', 'request body content', {CustomHeader => 'Value'}); # Requests can optionally automatically follow redirects and auth, defaults to # false $client->setFollow(1); #It is possible to access the L object REST::Client is using to #make requests, and set advanced options on it, for instance: $client->getUseragent()->proxy(['http'], 'http://proxy.example.com/'); # request responses can be written directly to a file $client->setContentFile( "FileName" ); # or call back method $client->setContentFile( \&callback_method ); # see LWP::UserAgent for how to define callback methods =head1 DESCRIPTION REST::Client provides a simple way to interact with HTTP RESTful resources. =head1 METHODS =head2 Construction and setup =head3 new ( [%$config] ) Construct a new REST::Client. Takes an optional hash or hash reference or config flags. Each config flag also has get/set accessors of the form getHost/setHost, getUseragent/setUseragent, etc. These can be called on the instantiated object to change or check values. The config flags are: =over 4 =item host A default host that will be prepended to all requests using relative URLs. Allows you to just specify the path when making requests. The default is undef - you must include the host in your requests. =item timeout A timeout in seconds for requests made with the client. After the timeout the client will return a 500. The default is 5 minutes. =item cert The path to a X509 certificate file to be used for client authentication. The default is to not use a certificate/key pair. =item key The path to a X509 key file to be used for client authentication. The default is to not use a certificate/key pair. =item ca The path to a certificate authority file to be used to verify host certificates. The default is to not use a certificates authority. =item pkcs12 The path to a PKCS12 certificate to be used for client authentication. =item pkcs12password The password for the PKCS12 certificate specified with 'pkcs12'. =item follow Boolean that determins whether REST::Client attempts to automatically follow redirects/authentication. The default is false. =item useragent An L object, ready to make http requests. REST::Client will provide a default for you if you do not set this. =back =head3 addHeader ( $header_name, $value ) Add a custom header to any requests made by this client. =head3 buildQuery ( [...] ) A convienience wrapper around URI::query_form for building query strings from a variety of data structures. See L Returns a scalar query string for use in URLs. =head2 Request Methods Each of these methods makes an HTTP request, sets the internal state of the object, and returns the object. They can be combined with the response methods, such as: print $client->GET('/search/?q=foobar')->responseContent(); =head3 GET ( $url, [%$headers] ) Preform an HTTP GET to the resource specified. Takes an optional hashref of custom request headers. =head3 PUT ($url, [$body_content, %$headers] ) Preform an HTTP PUT to the resource specified. Takes an optional body content and hashref of custom request headers. =head3 PATCH ( $url, [$body_content, %$headers] ) Preform an HTTP PATCH to the resource specified. Takes an optional body content and hashref of custom request headers. =head3 POST ( $url, [$body_content, %$headers] ) Preform an HTTP POST to the resource specified. Takes an optional body content and hashref of custom request headers. =head3 DELETE ( $url, [%$headers] ) Preform an HTTP DELETE to the resource specified. Takes an optional hashref of custom request headers. =head3 OPTIONS ( $url, [%$headers] ) Preform an HTTP OPTIONS to the resource specified. Takes an optional hashref of custom request headers. =head3 HEAD ( $url, [%$headers] ) Preform an HTTP HEAD to the resource specified. Takes an optional hashref of custom request headers. =head3 request ( $method, $url, [$body_content, %$headers] ) Issue a custom request, providing all possible values. =head2 Response Methods Use these methods to gather information about the last requset performed. =head3 responseCode () Return the HTTP response code of the last request =head3 responseContent () Return the response body content of the last request =head3 responseHeaders() Returns a list of HTTP header names from the last response =head3 responseHeader ( $header ) Return a HTTP header from the last response =head3 responseXpath () A convienience wrapper that returns a L xpath context for the body content. Assumes the content is XML. =head1 TODO Caching, content-type negotiation, readable handles for body content. =head1 AUTHORS =over 4 =item * Miles Crawford =item * Kevin L. Kane =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2008 by Miles Crawford. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut REST-Client-281/MANIFEST.SKIP0000644000175000017500000000102214157202615015161 0ustar huettelhuettel# Avoid version control files. \.gitignore$ \.git$ # Avoid Makemaker generated and utility files. \bMakefile$ \bblib \bMakeMaker-\d \bpm_to_blib$ \bblibdirs$ ^MYMETA\.yml$ ^MYMETA\.json$ # Avoid Module::Build generated and utility files. \bBuild$ \bBuild.bat$ \b_build .tar.gz$ # Avoid tars and their unpacked directory trees ^REST-Client # Avoid temp and backup files. ~$ \.tmp$ \.old$ \.bak$ \#$ \b\.# # NYTProf profiling output nytprof # Devel::Cover output ^cover_db # coding documentation not for distribution \bdoc\b REST-Client-281/Makefile.PL0000644000175000017500000000276214157202615015251 0ustar huettelhuettel# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.024. use strict; use warnings; use 5.008000; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "A simple client for interacting with RESTful http/https resources", "AUTHOR" => "Miles Crawford , Kevin L. Kane ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "REST-Client", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.008000", "NAME" => "REST::Client", "PREREQ_PM" => { "Carp" => 0, "LWP::Protocol::https" => 0, "LWP::UserAgent" => 0, "URI" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "HTTP::Server::Simple" => 0, "Test::More" => 0 }, "VERSION" => 281, "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "HTTP::Server::Simple" => 0, "LWP::Protocol::https" => 0, "LWP::UserAgent" => 0, "Test::More" => 0, "URI" => 0, "constant" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); REST-Client-281/META.json0000644000175000017500000000355314157202615014717 0ustar huettelhuettel{ "abstract" : "A simple client for interacting with RESTful http/https resources", "author" : [ "Miles Crawford ", "Kevin L. Kane " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.024, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "REST-Client", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "LWP::Protocol::https" : "0", "LWP::UserAgent" : "0", "URI" : "0", "constant" : "0", "perl" : "v5.8.0", "strict" : "0", "warnings" : "0" }, "suggests" : { "XML::LibXML" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "HTTP::Server::Simple" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/milescrawford/cpan-rest-client/issues" }, "homepage" : "https://github.com/milescrawford/cpan-rest-client", "repository" : { "type" : "git", "url" : "https://github.com/milescrawford/cpan-rest-client.git", "web" : "https://github.com/milescrawford/cpan-rest-client" } }, "version" : "281", "x_generated_by_perl" : "v5.34.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.27", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } REST-Client-281/t/0000755000175000017500000000000014157202615013533 5ustar huettelhuettelREST-Client-281/t/00-report-prereqs.dd0000644000175000017500000000263614157202615017262 0ustar huettelhuetteldo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'LWP::Protocol::https' => '0', 'LWP::UserAgent' => '0', 'URI' => '0', 'constant' => '0', 'perl' => 'v5.8.0', 'strict' => '0', 'warnings' => '0' }, 'suggests' => { 'XML::LibXML' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'HTTP::Server::Simple' => '0', 'Test::More' => '0' } } }; $x; }REST-Client-281/t/00-report-prereqs.t0000644000175000017500000001345214157202615017134 0ustar huettelhuettel#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.028 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass('Reported prereqs'); # vim: ts=4 sts=4 sw=4 et: REST-Client-281/t/basic.t0000644000175000017500000001345714157202615015013 0ustar huettelhuetteluse strict; use warnings; unshift @INC, "../lib"; use Test::More; # Check testing prereqs my $run_tests = 1; eval { die "HTTP::Server::Simple misbehaves on Windows" if $^O =~ /MSWin/; require HTTP::Server::Simple; }; if($@){ diag("Won't run tests because: $@"); $run_tests = 0; } SKIP: { skip('test prereqs not met') unless $run_tests; use_ok('REST::Client'); my $port = 7657; my $pid = REST::Client::TestServer->new($port)->background(); eval { # Initializing and configuring my $client = REST::Client->new(); ok( $client, "Client returned from new()" ); ok( ref($client) =~ /REST::Client/, "Client returned from new() is blessed" ); my $config = { host => 'https://example.com', cert => '/path/to/ssl.crt', key => '/path/to/ssl.key', ca => '/path/to/ca.file', timeout => 10, }; $client = REST::Client->new($config); is( $client->getHost(), $config->{'host'}, 'host accessor works' ); is( $client->getCert(), $config->{'cert'}, 'cert accessor works' ); is( $client->getKey(), $config->{'key'}, 'key accessor works' ); is( $client->getCa(), $config->{'ca'}, 'ca accessor works' ); is( $client->getTimeout(), $config->{'timeout'}, 'timeout accessor works' ); $config = { host => 'http://example.com', cert => '/path/from/ssl.crt', key => '/path/from/ssl.key', ca => '/path/from/ca.file', timeout => 60, }; is( $client->setHost( $config->{'host'} ), $config->{'host'}, 'host setter works' ); is( $client->setCert( $config->{'cert'} ), $config->{'cert'}, 'cert setter works' ); is( $client->setKey( $config->{'key'} ), $config->{'key'}, 'key setter works' ); is( $client->setCa( $config->{'ca'} ), $config->{'ca'}, 'ca setter works' ); is( $client->setTimeout( $config->{'timeout'} ), $config->{'timeout'}, 'timeout setter works' ); is( $client->getHost(), $config->{'host'}, 'host accessor works' ); is( $client->getCert(), $config->{'cert'}, 'cert accessor works' ); is( $client->getKey(), $config->{'key'}, 'key accessor works' ); is( $client->getCa(), $config->{'ca'}, 'ca accessor works' ); is( $client->getTimeout(), $config->{'timeout'}, 'timeout accessor works' ); # Basic requests $client = REST::Client->new( { host => "127.0.0.1:$port", } ); is( $client->GET("/"), $client, "Client returns self" ); is( $client->PUT("/"), $client, "Client returns self" ); is( $client->POST("/"), $client, "Client returns self" ); is( $client->PATCH("/"), $client, "Client returns self" ); is( $client->DELETE("/"), $client, "Client returns self" ); is( $client->OPTIONS("/"), $client, "Client returns self" ); is( $client->HEAD("/"), $client, "Client returns self" ); is( $client->request( 'GET', "/", '', {} ), $client, "Client returns self" ); my $path = "/ok/" . time() . "/"; is( $client->GET($path)->responseContent(), $path, "GET content present" ); is( $client->PUT($path)->responseContent(), $path, "PUT content present" ); is( $client->PATCH($path)->responseContent(), $path, "PATCH content present" ); is( $client->POST($path)->responseContent(), $path, "POST content present" ); is( $client->DELETE($path)->responseContent(), $path, "DELETE content present" ); is( $client->OPTIONS($path)->responseContent(), $path, "OPTIONS content present" ); is( $client->HEAD($path)->responseContent(), '', "HEAD content present" ); is( $client->request( 'GET', $path, '', {} ), $client, "request() content present" ); is( $client->GET($path)->responseCode(), 200, "Success code" ); $path = "/error/"; is( $client->GET($path)->responseCode(), 400, "Error code" ); $path = "/bogus/"; is( $client->GET($path)->responseCode(), 404, "Not found code" ); ok(scalar($client->responseHeaders()), 'Header names available'); ok( $client->responseHeader('Client-Response-Num'), 'Can pull a header'); my $fn = "content_file_test"; $client->setContentFile( $fn ); $path = "/ok/" . time() . "/"; $client->GET( $path ); open( my $fh, "<", $fn ); my $test; while( my $data = <$fh> ) { $test .= $data; } is( $test, $path, "GET into ContentFile (filename) works" ); `rm $fn`; $test = ""; my $callback = sub { my ( $data, $resp, $prot ) = @_; $test .= $data; }; $client->setContentFile( $callback ); $client->GET( $path ); is( $test, $path, "GET into ContentFile (callback) works" ); $client->setContentFile( undef ); }; warn "Tests died: $@" if $@; kill 15, $pid; } done_testing(); exit; package REST::Client::TestServer; BEGIN{ eval 'require HTTP::Server::Simple::CGI;'; our @ISA = qw(HTTP::Server::Simple::CGI); } sub handle_request { my ( $self, $cgi ) = @_; my $path = $cgi->path_info(); if ( $path =~ /ok/ ) { print "HTTP/1.0 200 OK\r\n"; } elsif ( $path =~ /error/ ) { print "HTTP/1.0 400 ERROR\r\n"; } else { print "HTTP/1.0 404 NOT FOUND\r\n"; } print "\n$path"; } sub valid_http_method { my $self = shift; my $method = shift or return 0; return $method =~ /^(?:GET|PATCH|POST|HEAD|PUT|DELETE|OPTIONS)$/; } 1; REST-Client-281/README.md0000644000175000017500000000013614157202615014547 0ustar huettelhuettel# REST::Client REST::Client module for CPAN. See http://search.cpan.org/perldoc?REST::Client REST-Client-281/dist.ini0000644000175000017500000000175414157202615014743 0ustar huettelhuettelname = REST-Client main_module = lib/REST/Client.pm author = Miles Crawford author = Kevin L. Kane license = Perl_5 copyright_holder = Miles Crawford copyright_year = 2008 [VersionFromMainModule] [MetaResources] homepage = https://github.com/milescrawford/cpan-rest-client bugtracker.web = https://github.com/milescrawford/cpan-rest-client/issues repository.url = https://github.com/milescrawford/cpan-rest-client.git repository.web = https://github.com/milescrawford/cpan-rest-client repository.type = git [GatherDir] [MetaJSON] [MakeMaker] [Git::Check] [Git::Commit] commit_msg = Release %N %v%n%n%c [Git::Tag] tag_format = %N-%v tag_message = Release %N %v [Git::Push] [AutoPrereqs] skip = XML::LibXML [Prereqs] perl = 5.8.0 LWP::Protocol::https = 0 [Prereqs / RuntimeSuggests] XML::LibXML = 0 [TestRelease] [ConfirmRelease] [UploadToCPAN] [PodWeaver] [Test::ReportPrereqs] REST-Client-281/Changes0000644000175000017500000000434314157202615014567 0ustar huettelhuettel History for the REST-Client Perl distribution 281 2021-12-17 * Allow arbitrary request verbs (RT #124620) 280 2021-12-14 * Convert build system to MakeMaker and Dist::Zilla Fixes the installation on recent Perl without '.' in @INC (RT #122263, RT #120854) * Do not prepend default host to absolute URLs (RT #119790) * Point to Github for source repository and issue tracker 273 * Add ContentFile that will allow writing responses directly to file or process using a call back through LWP::UserAgent * Seperated CA file from SSL cert and SSL key directives to allow for hostname verificaiton and ca file specification independently. Thanks David Imbs. * No longer depends on Crypt::SSLeay 272 * Fix bug that didn't allow false PUT content. Thanks Thomas Hörndlein! 271 * Move to LWP 6.x style SSL setup. Thanks Martin Drasar and Joel Crosswhite, for reports and testing. 249 * Remove Makefile from distribution. 245 * Fix test dependencies. 243 * Gave up on counting tests correctly, use done_testing(). 240 * Fix embarassing test-count mismatch. Thanks Wes Young. 236 * Added PATCH support by applying Scott Call's PATCH patch. Thanks! 217 * Disabled use of http::server::simple on windows, suggested by Adam Kennedy, thanks. 171 * Improved POD with better organization and a fix suggested by Joshua Barratt (Thanks!) * Added support for PKCS12 certificates in the config API, suggested by Sabst (Thanks!) 164 * Added a responseHeaders() method * Added sanity tests of responseHeaders() and responseHeader() 150 * Made the tests smarter about skipping when required libs not present. 134 * Added a method for accessing the LWP::UserAgent. * Added user agent config. * Cached user agent for all requests. * Improved pod. * Basic tests. 118 * Changed default behavior to not follow redirects. * Added an option to re-enable original auto-following behavior. 95 *Fixed http://rt.cpan.org/Public/Bug/Display.html?id=43819 - thanks Russ. 88 * Added html content-type detection to responseXPath to avoid xmlns issues when parsing html/xhtml. 62 * Switched to parse_string in the XPath convienince function. parse_html_string was causing trouble with plain XML. 57 *added changes *unmade a CPAN mistake 56 *initial release