3 use Test::More skip_all => "Not performing POST";
5 ######################### We start with some black magic to print on failure.
7 # Change 1..1 below to 1..last_test_to_print .
10 END {print "not ok 1\n" unless $::loaded;}
15 ######################### End of black magic.
19 use ExtUtils::MakeMaker qw(prompt);
21 # Read URL to get, defaulting to environment variable if supplied
22 my $defurl=$ENV{CURL_TEST_URL} || "http://www.google.com/";
23 my $url = prompt("# Please enter an URL to fetch",$defurl);
25 print "1..0 # No test URL supplied - skipping test\n";
29 print "ok ".++$count."\n";
31 # Init the curl session
32 my $curl = WWW::Curl::Easy->new();
36 print "ok ".++$count."\n";
38 $curl->setopt(CURLOPT_NOPROGRESS, 1);
39 $curl->setopt(CURLOPT_FOLLOWLOCATION, 1);
40 $curl->setopt(CURLOPT_TIMEOUT, 30);
42 open HEAD, ">head.out";
43 $curl->setopt(CURLOPT_WRITEHEADER, *HEAD);
44 print "ok ".++$count."\n";
46 open BODY, ">body.out";
47 $curl->setopt(CURLOPT_FILE,*BODY);
48 print "ok ".++$count."\n";
50 $curl->setopt(CURLOPT_URL, $url);
52 print "ok ".++$count."\n";
59 # print STDERR "\nperl read_callback has been called!\n";
60 # print STDERR "max data size: $maxlen - need $read_max bytes\n";
62 my $len=int($read_max/3)+1;
63 my $data = chr(ord('A')+rand(26))x$len;
64 # print STDERR "generated max/3=", int($read_max/3)+1, " characters to be uploaded - $data.\n";
65 $read_max=$read_max-length($data);
73 # test post/read callback functions - requires a url which accepts posts, or it fails!
76 $curl->setopt(CURLOPT_READFUNCTION,\&read_callb);
77 $curl->setopt(CURLOPT_INFILESIZE,$read_max );
78 $curl->setopt(CURLOPT_UPLOAD,1 );
79 $curl->setopt(CURLOPT_CUSTOMREQUEST,"POST" );
81 if ($curl->perform() != 0) {
84 print "ok ".++$count."\n";