File: response.t

package info (click to toggle)
libnet-httpserver-perl 1.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 576 kB
  • sloc: perl: 2,763; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
use lib "t/lib";
use Test::More tests=>26;

BEGIN{ use_ok( "Net::HTTPServer::Response" ); }

my $response = new Net::HTTPServer::Response();
ok( defined($response), "new()");
isa_ok( $response, "Net::HTTPServer::Response");

my @build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 200\r\n\r\n",""] , "_build: Blank" );

$response->Header("Test","test");
ok( $response->Header("Test"), "Header Test exists");
is( $response->Header("Test"), "test", "Header Test == test");

@build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 200\nTest: test\r\n\r\n",""] , "_build: Header" );

$response->Cookie("Test","test");

@build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 200\nTest: test\nSet-Cookie: Test=test\r\n\r\n",""] , "_build: Cookie" );

$response->Cookie("Test","test",expires=>"expires",domain=>"domain",path=>"path",secure=>1);

@build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 200\nTest: test\nSet-Cookie: Test=test;domain=domain;expires=expires;path=path;secure\r\n\r\n",""] , "_build: Full cookie" );

is( $response->Code(), 200, "Code == 200");
$response->Code(400);
isnt( $response->Code(), 200, "Code != 200");
is( $response->Code(), 400, "Code == 400");

@build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 400\nTest: test\nSet-Cookie: Test=test;domain=domain;expires=expires;path=path;secure\r\n\r\n",""] , "_build: New code" );

is( $response->Body(), "", "Body == " );
$response->Body("Test body");
is( $response->Body(), "Test body", "Body == Test body" );

@build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 400\nTest: test\nSet-Cookie: Test=test;domain=domain;expires=expires;path=path;secure\r\n\r\n","Test body"] , "_build: Body" );

is( $response->Body(), "Test body", "Body == Test body" );
$response->Clear();
is( $response->Body(), "", "Body == " );

@build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 400\nTest: test\nSet-Cookie: Test=test;domain=domain;expires=expires;path=path;secure\r\n\r\n",""] , "_build: Clear" );

is( $response->Body(), "", "Body == " );
$response->Print("Test");
is( $response->Body(), "Test", "Body == Test" );
$response->Print(" body");
is( $response->Body(), "Test body", "Body == Test body" );


@build = $response->_build();
is_deeply( \@build, ["HTTP/1.1 400\nTest: test\nSet-Cookie: Test=test;domain=domain;expires=expires;path=path;secure\r\n\r\n","Test body"] , "_build: Print" );

my $response2 = new Net::HTTPServer::Response();
ok( defined($response2), "new()");
isa_ok( $response2, "Net::HTTPServer::Response");

$response2->Redirect("http://www.server.com/path");
@build = $response2->_build();
is_deeply( \@build, ["HTTP/1.1 307\nLocation: http://www.server.com/path\r\n\r\n",""] , "_build: Redirect" );