HTTP-Easy

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

SYNOPSIS
        use HTTP::Easy::Headers;
        my $h = "Connection: close\015\012".
        "Expect: continue-100\015\012".
        "Content-Type: text/html";

        my $hash = HTTP::Easy::Headers->decode($h);

        $hash->{connection};     # 'close'
        $hash->{expect};         # 'continue-100'
        $hash->{'content-type'}; # 'text/html'

        my $hdr = HTTP::Easy::Headers->encode($hash);

        use HTTP::Easy::Cookie;

        my $cookie_jar = HTTP::Easy::Cookie->decode($hdr->{cookie});

        $hdr->{cookie} = HTTP::Easy::Cookie->encode($cookie_jar, host => 'example.net', path => '/path' );

AUTHOR

lib/HTTP/Easy.pm  view on Meta::CPAN


    use HTTP::Easy::Headers;
    my $h = "Connection: close\015\012".
        "Expect: continue-100\015\012".
        "Content-Type: text/html";

    my $hash = HTTP::Easy::Headers->decode($h);

    $hash->{connection};     # 'close'
    $hash->{expect};         # 'continue-100'
    $hash->{'content-type'}; # 'text/html'
    
    my $hdr = HTTP::Easy::Headers->encode($hash);
    
    use HTTP::Easy::Cookie;
    
    my $cookie_jar = HTTP::Easy::Cookie->decode($hdr->{cookie});
    
    $hdr->{cookie} = HTTP::Easy::Cookie->encode($cookie_jar, host => 'example.net', path => '/path' );
    
=head1 AUTHOR

t/01-headers-decode.t  view on Meta::CPAN


my $hash;
my $h = "Connection: close\015\012".
        "Expect: continue-100\015\012".
        "Content-Type: text/html";

$hash = $mod->decode($h);

is($hash->{connection},     'close',        'right value');
is($hash->{expect},         'continue-100', 'right value');
is($hash->{'content-type'}, 'text/html',    'right value');

# garbled
$h = "Host:www.ru\012".
     "Host:another.com\012".
     "DaTe:  somedate  \012".
     "X-Someval: some part\012".
         "\t  continue\012".
     "Test";
is_deeply
	$hash = $mod->decode($h),

t/02-headers-encode.t  view on Meta::CPAN

use Test::More tests => 13;

my $mod = 'HTTP::Easy::Headers';
{no strict; ${$mod.'::NO_XS'} = 1;}
use_ok $mod;

my $hdr;
my $h = {
	connection => 'close',
	ExPeCt => 'continue-100',
	'content-type' => 'text/html',
	date => undef,
};

# Static method

$hdr = $mod->encode($h);
my @lines = split /\015\012/, $hdr;

is 0+@lines, 3, '3 lines' or diag $hdr;
ok + (1 == grep { $_ eq 'Connection: close' } @lines), 'connection' or diag $hdr;
ok + (1 == grep { $_ eq 'Expect: continue-100' } @lines), 'expect' or diag $hdr;
ok + (1 == grep { $_ eq 'Content-type: text/html' } @lines), 'content-type' or diag $hdr;

# Static method on object

$h = $mod->new($h);

$hdr = $mod->encode($h);
my @lines = split /\015\012/, $hdr;

is 0+@lines, 3, '3 lines' or diag $hdr;
ok + (1 == grep { $_ eq 'Connection: close' } @lines), 'connection' or diag $hdr;
ok + (1 == grep { $_ eq 'Expect: continue-100' } @lines), 'expect' or diag $hdr;
ok + (1 == grep { $_ eq 'Content-type: text/html' } @lines), 'content-type' or diag $hdr;

# Object method

$hdr = $h->encode();
my @lines = split /\015\012/, $hdr;

is 0+@lines, 3, '3 lines' or diag $hdr;
ok + (1 == grep { $_ eq 'Connection: close' } @lines), 'connection' or diag $hdr;
ok + (1 == grep { $_ eq 'Expect: continue-100' } @lines), 'expect' or diag $hdr;
ok + (1 == grep { $_ eq 'Content-type: text/html' } @lines), 'content-type' or diag $hdr;



( run in 1.164 second using v1.01-cache-2.11-cpan-524268b4103 )