-
-
Save omega/88223 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use Test::More tests => 7; | |
use WWW::Curl::Easy; | |
use HTTP::Request; | |
my $url = 'http://en.wikipedia.org/wiki/Main_Page'; | |
my $req = HTTP::Request->new( GET => $url ); | |
isa_ok( $req, 'HTTP::Request' ); | |
my $c; | |
{ | |
my $curl = new WWW::Curl::Easy; | |
$curl->setopt(CURLOPT_VERBOSE,1); | |
$curl->setopt( CURLOPT_HEADER, 1 ); | |
$curl->setopt( CURLOPT_NOPROGRESS, 1 ); | |
# my $url = $req->uri->as_string; | |
$curl->setopt( CURLOPT_URL, $url ); | |
is( $curl->getinfo(CURLINFO_EFFECTIVE_URL), $url ); | |
if ( $req->method eq 'POST' ) { | |
$curl->setopt( CURLOPT_POST, 1 ); | |
$curl->setopt( CURLOPT_POSTFIELDS, $req->content ); | |
} | |
my @headers; | |
foreach my $h ( +$req->headers->header_field_names ) { | |
warn "h: $h"; | |
push( @headers, "$h: " . $req->header($h) ); | |
} | |
if ( scalar(@headers) ) { | |
$curl->setopt( CURLOPT_HTTPHEADER, \@headers ); | |
} | |
$curl->setopt(CURLOPT_WRITEFUNCTION, sub { | |
my $chunk = shift; | |
$c = $chunk; | |
return length($chunk); | |
}); | |
my $retcode = $curl->perform; | |
is( $retcode, 0 ); | |
is( $curl->strerror($retcode), 'no error' ); | |
} | |
{ | |
my $curl = new WWW::Curl::Easy; | |
$curl->setopt(CURLOPT_VERBOSE,1); | |
$curl->setopt( CURLOPT_HEADER, 1 ); | |
$curl->setopt( CURLOPT_NOPROGRESS, 1 ); | |
# my $url = $req->uri->as_string; | |
$curl->setopt( CURLOPT_URL, $req->uri->as_string ); | |
is( $curl->getinfo(CURLINFO_EFFECTIVE_URL), $url ); | |
if ( $req->method eq 'POST' ) { | |
$curl->setopt( CURLOPT_POST, 1 ); | |
$curl->setopt( CURLOPT_POSTFIELDS, $req->content ); | |
} | |
my @headers; | |
foreach my $h ( +$req->headers->header_field_names ) { | |
warn "h: $h"; | |
push( @headers, "$h: " . $req->header($h) ); | |
} | |
if ( scalar(@headers) ) { | |
$curl->setopt( CURLOPT_HTTPHEADER, \@headers ); | |
} | |
$curl->setopt(CURLOPT_WRITEFUNCTION, sub { | |
my $chunk = shift; | |
$c = $chunk; | |
return length($chunk); | |
}); | |
my $retcode = $curl->perform; | |
is( $retcode, 0 ); | |
is( $curl->strerror($retcode), 'no error' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Macintosh:www-curl-simple bolav$ prove -v -l t/99.break-easy.t | |
t/99.break-easy.... | |
1..7 | |
ok 1 - The object isa HTTP::Request | |
ok 2 | |
ok 3 | |
ok 4 | |
ok 5 | |
not ok 6 | |
not ok 7 | |
# Failed test at t/99.break-easy.t line 81. | |
# got: '6' | |
# expected: '0' | |
# Failed test at t/99.break-easy.t line 83. | |
# got: 'couldn't resolve host name' | |
# expected: 'no error' | |
# Looks like you failed 2 tests of 7. | |
Dubious, test returned 2 (wstat 512, 0x200) | |
Failed 2/7 subtests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@etchbuild64:/build# perl t.pl | |
1..7 | |
ok 1 - The object isa HTTP::Request | |
ok 2 | |
* About to connect() to en.wikipedia.org port 80 | |
* Trying 91.198.174.2... * connected | |
* Connected to en.wikipedia.org (91.198.174.2) port 80 | |
> GET /wiki/Main_Page HTTP/1.1 | |
Host: en.wikipedia.org | |
Accept: */* | |
< HTTP/1.0 200 OK | |
< Date: Tue, 31 Mar 2009 15:15:54 GMT | |
< Server: Apache | |
< X-Powered-By: PHP/5.2.4-2ubuntu5wm1 | |
< Cache-Control: private, s-maxage=0, max-age=0, must-revalidate | |
< Content-Language: en | |
< Vary: Accept-Encoding,Cookie | |
< X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;string-contains=enwikiToken;string-contains=enwikiLoggedOut;string-contains=enwiki_session;string-contains=centralauth_Token;string-contains=centralauth_Session;string-contains=centralauth_LoggedOut | |
< Last-Modified: Tue, 31 Mar 2009 15:14:06 GMT | |
< Content-Length: 59498 | |
< Content-Type: text/html; charset=utf-8 | |
< X-Cache: MISS from sq39.wikimedia.org | |
< X-Cache-Lookup: HIT from sq39.wikimedia.org:3128 | |
< Age: 1 | |
< X-Cache: HIT from knsq29.knams.wikimedia.org | |
< X-Cache-Lookup: HIT from knsq29.knams.wikimedia.org:3128 | |
< X-Cache: MISS from knsq29.knams.wikimedia.org | |
< X-Cache-Lookup: MISS from knsq29.knams.wikimedia.org:80 | |
< Via: 1.1 sq39.wikimedia.org:3128 (squid/2.7.STABLE6), 1.0 knsq29.knams.wikimedia.org:3128 (squid/2.7.STABLE6), 1.0 knsq29.knams.wikimedia.org:80 (squid/2.7.STABLE6) | |
< Connection: close | |
* Closing connection #0 | |
ok 3 | |
ok 4 | |
not ok 5 | |
# Failed test in t.pl at line 59. | |
# got: '' | |
# expected: 'http://en.wikipedia.org/wiki/Main_Page' | |
not ok 6 | |
# Failed test in t.pl at line 82. | |
# got: '6' | |
# expected: '0' | |
not ok 7 | |
# Failed test in t.pl at line 84. | |
# got: 'couldn't resolve host name' | |
# expected: 'no error' | |
# Looks like you failed 3 tests of 7. | |
root@etchbuild64:/build# vi t.pl | |
bash: vi: command not found | |
root@etchbuild64:/build# perl t.pl | |
1..7 | |
ok 1 - The object isa HTTP::Request | |
ok 2 | |
* About to connect() to en.wikipedia.org port 80 | |
* Trying 91.198.174.2... * connected | |
* Connected to en.wikipedia.org (91.198.174.2) port 80 | |
> GET /wiki/Main_Page HTTP/1.1 | |
Host: en.wikipedia.org | |
Accept: */* | |
< HTTP/1.0 200 OK | |
< Date: Tue, 31 Mar 2009 15:16:39 GMT | |
< Server: Apache | |
< X-Powered-By: PHP/5.2.4-2ubuntu5wm1 | |
< Cache-Control: private, s-maxage=0, max-age=0, must-revalidate | |
< Content-Language: en | |
< Vary: Accept-Encoding,Cookie | |
< X-Vary-Options: Accept-Encoding;list-contains=gzip,Cookie;string-contains=enwikiToken;string-contains=enwikiLoggedOut;string-contains=enwiki_session;string-contains=centralauth_Token;string-contains=centralauth_Session;string-contains=centralauth_LoggedOut | |
< Last-Modified: Tue, 31 Mar 2009 15:14:06 GMT | |
< Content-Length: 59498 | |
< Content-Type: text/html; charset=utf-8 | |
< X-Cache: MISS from sq39.wikimedia.org | |
< X-Cache-Lookup: HIT from sq39.wikimedia.org:3128 | |
< X-Cache: HIT from knsq29.knams.wikimedia.org | |
< X-Cache-Lookup: HIT from knsq29.knams.wikimedia.org:3128 | |
< X-Cache: MISS from knsq23.knams.wikimedia.org | |
< X-Cache-Lookup: MISS from knsq23.knams.wikimedia.org:80 | |
< Via: 1.1 sq39.wikimedia.org:3128 (squid/2.7.STABLE6), 1.0 knsq29.knams.wikimedia.org:3128 (squid/2.7.STABLE6), 1.0 knsq23.knams.wikimedia.org:80 (squid/2.7.STABLE6) | |
< Connection: close | |
* Closing connection #0 | |
ok 3 | |
ok 4 | |
not ok 5 | |
# Failed test in t.pl at line 60. | |
# got: '' | |
# expected: 'http://en.wikipedia.org/wiki/Main_Page' | |
* getaddrinfo(3) failed for;P:80 | |
* Couldn't resolve host ;P' | |
* Closing connection #0 | |
not ok 6 | |
# Failed test in t.pl at line 83. | |
# got: '6' | |
# expected: '0' | |
not ok 7 | |
# Failed test in t.pl at line 85. | |
# got: 'couldn't resolve host name' | |
# expected: 'no error' | |
# Looks like you failed 3 tests of 7. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment