/[cvs]/joko/TestArea/perl/runtime/POE/net/client_http.pl
ViewVC logotype

Annotation of /joko/TestArea/perl/runtime/POE/net/client_http.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sun May 11 21:48:54 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
initial commit

1 joko 1.1 #!/usr/bin/perl -w
2    
3     use strict;
4    
5     use HTTP::Request::Common qw(GET POST);
6    
7     sub POE::Kernel::ASSERT_DEFAULT () { 1 }
8     use POE qw(Component::Client::HTTP);
9    
10     sub DEBUG () { 1 }
11     sub TEST_BIG_STUFF () { 0 } # requires localhost:19
12    
13     $| = 1;
14     print "1..2\n";
15    
16     my @test_results = ( 'not ok 1', 'not ok 2' );
17    
18     #------------------------------------------------------------------------------
19    
20     sub client_start {
21     my ($kernel, $heap) = @_[KERNEL, HEAP];
22    
23     DEBUG and warn "client starting...\n";
24    
25     $kernel->post( weeble => request => got_response =>
26     GET 'http://www.ilo.de/ilo2000/'
27     );
28    
29     #$kernel->post( weeble => request => got_response =>
30     # GET 'http://poe.perl.org/misc/test.html'
31     # );
32    
33     #$kernel->post( weeble => request => got_response =>
34     # ( POST 'http://poe.perl.org/misc/test.cgi',
35     # [ cgi_field_one => '111',
36     # cgi_field_two => '222',
37     # cgi_field_six => '666',
38     # cgi_field_ten => 'AAA',
39     # ]
40     # )
41     # );
42    
43     if (TEST_BIG_STUFF) {
44     $kernel->post( weeble => request => got_response =>
45     GET 'http://127.0.0.1:19/'
46     );
47     }
48     }
49    
50     sub client_stop {
51     DEBUG and warn "client stopped...\n";
52     foreach (@test_results) {
53     print "$_\n";
54     }
55     }
56    
57     sub client_got_response {
58     my ($heap, $request_packet, $response_packet) = @_[HEAP, ARG0, ARG1];
59     my $http_request = $request_packet->[0];
60     my $http_response = $response_packet->[0];
61    
62     DEBUG and do {
63     warn "client got request...\n";
64    
65     my $response_string = $http_response->as_string();
66     $response_string =~ s/^/| /mg;
67    
68     print ",", '-' x 78, "\n";
69     print $response_string;
70     print "`", '-' x 78, "\n";
71     };
72    
73     my $request_path = $http_request->uri->path . ''; # stringify
74    
75     if ($http_response->code == 200) {
76     $test_results[0] = 'ok 1' if $request_path =~ m/\/test\.html$/;
77     $test_results[1] = 'ok 2' if $request_path =~ m/\/test\.cgi$/;
78     }
79     }
80    
81     #------------------------------------------------------------------------------
82    
83     # Create a weeble component.
84     POE::Component::Client::HTTP->spawn
85     ( MaxSize => 4096,
86     Timeout => 180,
87     );
88    
89     # Create a session that will make some requests.
90     POE::Session->create
91     ( inline_states =>
92     { _start => \&client_start,
93     _stop => \&client_stop,
94     got_response => \&client_got_response,
95     _signal => sub { 0 },
96     }
97     );
98    
99     # Run it all until done.
100     $poe_kernel->run();
101    
102     exit;

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed