9
sub j { join("|", @_) }
11
my $conf = HTTP::Config->new;
15
ok(j($conf->matching_items("http://www.example.com/foo")), 42);
16
ok(j($conf->remove_items), 42);
17
ok($conf->matching_items("http://www.example.com/foo"), 0);
19
$conf = HTTP::Config->new;
21
$conf->add_item("always");
22
$conf->add_item("GET", m_method => ["GET", "HEAD"]);
23
$conf->add_item("POST", m_method => "POST");
24
$conf->add_item(".com", m_domain => ".com");
25
$conf->add_item("secure", m_secure => 1);
26
$conf->add_item("not secure", m_secure => 0);
27
$conf->add_item("slash", m_host_port => "www.example.com:80", m_path_prefix => "/");
28
$conf->add_item("u:p", m_host_port => "www.example.com:80", m_path_prefix => "/foo");
29
$conf->add_item("success", m_code => "2xx");
32
my $request = HTTP::Request->new(HEAD => "http://www.example.com/foo/bar");
33
$request->header("User-Agent" => "Moz/1.0");
35
ok(j($conf->matching_items($request)), "u:p|slash|.com|GET|not secure|always");
37
$request->method("HEAD");
38
$request->uri->scheme("https");
40
ok(j($conf->matching_items($request)), ".com|GET|secure|always");
42
ok(j($conf->matching_items("http://activestate.com")), ".com|not secure|always");
45
my $response = HTTP::Response->new(200 => "OK");
46
$response->content_type("text/plain");
47
$response->content("Hello, world!\n");
48
$response->request($request);
50
ok(j($conf->matching_items($response)), ".com|success|GET|secure|always");
52
$conf->remove_items(m_secure => 1);
53
$conf->remove_items(m_domain => ".com");
54
ok(j($conf->matching_items($response)), "success|GET|always");
56
$conf->remove_items; # start fresh
57
ok(j($conf->matching_items($response)), "");
59
$conf->add_item("any", "m_media_type" => "*/*");
60
$conf->add_item("text", m_media_type => "text/*");
61
$conf->add_item("html", m_media_type => "html");
62
$conf->add_item("HTML", m_media_type => "text/html");
63
$conf->add_item("xhtml", m_media_type => "xhtml");
65
ok(j($conf->matching_items($response)), "text|any");
67
$response->content_type("application/xhtml+xml");
68
ok(j($conf->matching_items($response)), "xhtml|html|any");
70
$response->content_type("text/html");
71
ok(j($conf->matching_items($response)), "HTML|html|text|any");