don't cause uninitialized value warnings when debugging is off...
[Net-HTTPS-Any.git] / lib / Net / HTTPS / Any.pm
index 1812d06..d42b618 100644 (file)
@@ -82,7 +82,8 @@ our $VERSION = '0.09';
 =head1 DESCRIPTION
 
 This is a simple wrapper around either of the two available SSL
-modules.
+modules.  It offers a unified API for send GET and POST requests over HTTPS
+and receiving responses.
 
 It depends on Net::SSLeay _or_ ( Crypt::SSLeay and LWP::UserAgent ).
 
@@ -131,14 +132,14 @@ sub https_get {
     # accept a hashref or a list (keep it ordered)
     my $post_data = {};
     if (      exists($opts->{'args'}) && ref($opts->{'args'}) eq 'HASH'  ) {
-        $post_data = shift;
+        $post_data = $opts->{'args'};
     } elsif ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'ARRAY' ) {
         tie my %hash, 'Tie::IxHash', @{ $opts->{'args'} };
         $post_data = \%hash;
     }
 
     $opts->{'port'} ||= 443;
-    $opts->{"Content-Type"} ||= "application/x-www-form-urlencoded";
+    #$opts->{"Content-Type"} ||= "application/x-www-form-urlencoded";
 
     ### XXX referer!!!
     my %headers = ();
@@ -160,7 +161,8 @@ sub https_get {
         import Net::SSLeay qw(get_https make_headers);
         my $headers = make_headers(%headers);
 
-        $Net::SSLeay::trace = $opts->{'debug'} if exists $opts->{'debug'};
+        $Net::SSLeay::trace = $opts->{'debug'}
+          if exists $opts->{'debug'} && $opts->{'debug'};
 
         my( $res_page, $res_code, @res_headers ) =
           get_https( $opts->{'host'},
@@ -246,7 +248,7 @@ sub https_post {
     # accept a hashref or a list (keep it ordered).  or a scalar of content.
     my $post_data = '';
     if (      exists($opts->{'args'}) && ref($opts->{'args'}) eq 'HASH'  ) {
-        $post_data = shift;
+        $post_data = $opts->{'args'};
     } elsif ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'ARRAY' ) {
         tie my %hash, 'Tie::IxHash', @{ $opts->{'args'} };
         $post_data = \%hash;
@@ -272,7 +274,8 @@ sub https_post {
 
         my $raw_data = ref($post_data) ? make_form(%$post_data) : $post_data;
 
-        $Net::SSLeay::trace = $opts->{'debug'} if exists $opts->{'debug'};
+        $Net::SSLeay::trace = $opts->{'debug'}
+          if exists $opts->{'debug'} && $opts->{'debug'};
 
         my( $res_page, $res_code, @res_headers ) =
           post_https( $opts->{'host'},