File: cookie-server

package info (click to toggle)
libtest-http-localserver-perl 0.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: perl: 793; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 942 bytes parent folder | download | duplicates (3)
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
#!perl -w
# Thanks to merlyn for nudging me and giving me this snippet!
use strict;

require HTTP::Daemon;

our $VERSION = '0.67';

$|++;

my $d = HTTP::Daemon->new or die;
print $d->url, "\n";

# How many requests do we expect?
my ($ex_user,$ex_pass) = @ARGV;

my $verbose = $ENV{TEST_HTTP_VERBOSE};

my $done = 0;
while (! $done and my $c = $d->accept) {
  while (my $req = $c->get_request) {
    if ($verbose) {
      warn "# Request URI: " . $req->url->path;
      my @lines = split "\n",$req->as_string;
      warn "# $_\n" for @lines;
    };

    my $res;
    my ($user,$pass);
    if ($req->url->path eq '/exit') {
        $done = 1;
        $res = HTTP::Response->new(200, "OK", undef, "done");
    };

    if ($verbose) {
      warn "---\n";
      my @lines = split "\n",$res->as_string;
      warn "# $_\n" for @lines;
    };
    $c->send_response($res);
  }
  $c->close;
  undef($c);
};