#!/usr/local/bin/perl # server.pl use HTTP::Daemon; use HTTP::Status; mkdir("/var/tmp/cluster") || die "/var/tmp/cluster probably already exists"; my $d = HTTP::Daemon->new(LocalPort => 8888, ReuseAddr => 1); print "Please contact me at: url, ">\n"; # TODO: make an external program get executed for each request # TODO: add errors while (my $c = $d->accept) { while (my $r = $c->get_request) { if ($r->uri->path eq '/quit') { goto OUTTAHERE; } my $dir = $0; $dir =~ s%/[^/]*$%%; my $method = $r->method; my $path = $r->uri->path; my $len = 0; if (length(${$r->content_ref}) > 0) { open CONTENT, ">/var/tmp/cosmos_server.content.gz" || die "cannot write content"; binmode(CONTENT); print CONTENT ${$r->content_ref}; close CONTENT; $len = `gzip -d new(map({split(/:\s/)} @fields)); $respstr =~ s/.*?\r?\n\r?\n//s; # body } my $retstat = $?; if ($code == 200 || $code == 404 || $code == 100) { $resp = HTTP::Response->new($code, $codestr, $header, $respstr); $c->send_response($resp); } else { $c->send_error($code) } } $c->close; undef($c); } OUTTAHERE: #### #!/usr/local/bin/perl #server_content.pl use Sys::Hostname qw/hostname/; use HTTP::Headers; my $respstr; if (rand(100) < 20) { print "Conflict 409\n\r\n\r\n"; exit(1); } if ($ARGV[0] eq 'HEAD') { $respstr = ' http://co1.search.live.net:88'; $respstr .= $ARGV[1]; $respstr .= < 0 0 128629751982538969 18446744073709551615 128632226810164042 3 sandbox ERWDX GETEOF2 # # #Authentication failed #0x00000000 #The operation succeeded #co1sch7080801 # } elsif ($ARGV[0] eq 'GET') { $respstr = ' http://portal.cosmos02-prod-co1.search.live.net:88'; $respstr .= $ARGV[1]; $respstr .= < 0 0 128629751982538969 18446744073709551615 128632226810164042 3 sandbox ERWDX GETEOF2 } elsif ($ARGV[0] eq 'POST') { $respstr = ' http://co1.search.live.net:88'; $respstr .= $ARGV[1]; $respstr .= < $ARGV[2] POSTEOF2 system("cat /var/tmp/cosmos_server.content>>/var/tmp/cluster/orgs_".hostname); } elsif ($ARGV[0] eq 'PUT') { $respstr = ' http://prod-co1.search.live.net:88'; $respstr .= $ARGV[1]; $respstr .= < $ARGV[2] PUTEOF2 system("cat /var/tmp/server.content>>/var/tmp/cluster/orgs_".hostname); } else { exit(1); } print "OK 200\nCache-Control: private\nContent-Length: ", length($respstr) ,"\nContent-Type: application/xml; charset=utf-8\nSet-Cookie: Session=F306972E-F9B0-4D13-958D-0A561AFD6985; Path=/\nProxy-Connection: Keep-Alive\r\n\r\n",$respstr;