Skip to content

Commit

Permalink
Added examples/getinfo.p6 to read the content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
azawawi committed Nov 17, 2012
1 parent cb6e49b commit 338fd6f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
28 changes: 28 additions & 0 deletions examples/getinfo.p6
@@ -0,0 +1,28 @@
#!/usr/bin/env perl6
use v6;

BEGIN { @*INC.push('lib') };

use Net::Curl;
use NativeCall;

my $curl = curl_easy_init;
die "Failed to curl_easy_init" unless $curl;

curl_easy_setopt($curl, CURLOPT_URL, 'http://www.example.com/');

my $res = curl_easy_perform($curl);

if CURLE_OK == $res {

# ask for the content-type
my $ct = CArray[int].new;
$res = curl_easy_getinfo($curl, CURLINFO_CONTENT_TYPE, $ct);

if (CURLE_OK == $res) && $ct {
printf("We received Content-Type: %s\n", $ct);
}

# always cleanup
curl_easy_cleanup($curl);
}
13 changes: 11 additions & 2 deletions lib/Net/Curl.pm6
Expand Up @@ -7,8 +7,11 @@ use NativeCall;


constant LIB = 'libcurl.so'; constant LIB = 'libcurl.so';


constant CURLOPT_URL is export = 10002;
constant CURLE_OK is export = 0; constant CURLINFO_STRING = 0x100000;
constant CURLOPT_URL is export = 10002;
constant CURLE_OK is export = 0;
constant CURLINFO_CONTENT_TYPE is export = CURLINFO_STRING + 18;


# Start a libcurl easy session # Start a libcurl easy session
sub curl_easy_init() sub curl_easy_init()
Expand Down Expand Up @@ -44,3 +47,9 @@ sub curl_easy_version()
is native(LIB) is native(LIB)
is export { ... }; is export { ... };


# Extract information from a curl handle
sub curl_easy_getinfo(OpaquePointer, int, CArray[int])
returns int
is native(LIB)
is export { ... };

0 comments on commit 338fd6f

Please sign in to comment.