Skip to content

Commit

Permalink
Get method sends headers if provided
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
cpin committed Jul 15, 2017
1 parent 243de4f commit c71bb0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
19 changes: 10 additions & 9 deletions META6.json
@@ -1,14 +1,15 @@
{
"perl" : "6.*",
"name" : "LWP::Simple",
"version" : "0.090",
"description" : "LWP::Simple quick & dirty implementation for Rakudo Perl 6",
"depends" : [ "MIME::Base64", "URI" ],
"provides" : {
"perl" : "6.*",
"name" : "LWP::Simple",
"version" : "0.090",
"description" : "LWP::Simple quick & dirty implementation for Rakudo Perl 6",
"depends" : [ "MIME::Base64", "URI" ],
"test-depends" : [ "JSON::Tiny" ],
"provides" : {
"LWP::Simple" : "lib/LWP/Simple.pm"
},
"author" : "Cosimo Streppone",
"authority" : "perl6",
"source-url" : "git://github.com/perl6/perl6-lwp-simple.git"
"author" : "Cosimo Streppone",
"authority" : "perl6",
"source-url" : "git://github.com/perl6/perl6-lwp-simple.git"
}

2 changes: 1 addition & 1 deletion lib/LWP/Simple.pm
Expand Up @@ -29,7 +29,7 @@ method base64encode ($user, $pass) {
}

method get (Str $url, %headers = {}) {
self.request_shell(RequestType::GET, $url)
self.request_shell(RequestType::GET, $url, %headers)
}

method delete (Str $url, %headers = {}) {
Expand Down
24 changes: 24 additions & 0 deletions t/get-headers.t
@@ -0,0 +1,24 @@
use v6;
use Test;

use LWP::Simple;
use JSON::Tiny;

plan 2;

if %*ENV<NO_NETWORK_TESTING> {
diag "NO_NETWORK_TESTING was set";
skip-rest("NO_NETWORK_TESTING was set");
exit;
}

my %headers =
"Accept" => "application/json",
"User-Agent" => "Perl 6",
;

my $html = LWP::Simple.get('http://httpbin.org/get', %headers);
my %json = from-json $html;

is %json<headers><User-Agent>, "Perl 6", "User agent header is sent by GET";
is %json<headers><Accept>, "application/json", "Accept header is sent by GET";

0 comments on commit c71bb0e

Please sign in to comment.