File: protosub.t

package info (click to toggle)
libwww-perl 6.78-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,008 kB
  • sloc: perl: 4,148; makefile: 10; sh: 6
file content (57 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
use Test::More;

use HTTP::Request ();
use LWP::UserAgent ();
use LWP::Protocol ();

LWP::Protocol::implementor(http => 'myhttp');

plan tests => 7;

# This test tries to make a custom protocol implementation by
# subclassing of LWP::Protocol.

my $ua = LWP::UserAgent->new;
$ua->proxy('ftp' => "http://www.sn.no/");

my $req = HTTP::Request->new(GET => 'ftp://foo/');
$req->header(Cookie => "perl=cool");
my $res = $ua->request($req);
isa_ok($res, 'HTTP::Response', 'sn.no: got a response');

#print $res->as_string;
is($res->code, 200, 'sn.no: code 200');
is($res->content, "Howdy\n", 'sn.no: content good');
exit;


{
    package myhttp;
    use parent 'LWP::Protocol';
    use Test::More;

    sub new {
        my $self = shift->SUPER::new(@_);
        my($prot) = @_;
        is($prot, "http", 'protocol: http');
        $self;
    }

    sub request {
        my $self = shift;
        my($request, $proxy, $arg, $size, $timeout) = @_;
        #print $request->as_string;

        is($proxy, "http://www.sn.no/", 'protocol request: proxy good');
        is($request->uri, "ftp://foo/", 'protocol request: uri good');
        is($request->header("cookie"), "perl=cool", 'protocol request: cookie good');

        my $res = HTTP::Response->new(200 => "OK");
        $res->content_type("text/plain");
        $res->date(time);
        $self->collect_once($arg, $res, "Howdy\n");
        $res;
    }
}