ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/httpd.pl
(Generate patch)

Comparing Coro/myhttpd/httpd.pl (file contents):
Revision 1.26 by root, Sun Aug 19 22:59:35 2001 UTC vs.
Revision 1.28 by root, Mon Aug 20 16:58:19 2001 UTC

9# at least on my machine, this thingy serves files 9# at least on my machine, this thingy serves files
10# quite a bit faster than apache, ;) 10# quite a bit faster than apache, ;)
11# and quite a bit slower than thttpd :( 11# and quite a bit slower than thttpd :(
12 12
13$SIG{PIPE} = 'IGNORE'; 13$SIG{PIPE} = 'IGNORE';
14 14
15our $accesslog;
16
17if ($ACCESS_LOG) {
18 use IO::Handle;
19 open $accesslog, ">>$ACCESS_LOG"
20 or die "$ACCESS_LOG: $!";
21 $accesslog->autoflush(1);
22}
23
15sub slog { 24sub slog {
16 my $level = shift; 25 my $level = shift;
17 my $format = shift; 26 my $format = shift;
18 printf "---: $format\n", @_; 27 printf "---: $format\n", @_;
19} 28}
141 150
142sub response { 151sub response {
143 my ($self, $code, $msg, $hdr, $content) = @_; 152 my ($self, $code, $msg, $hdr, $content) = @_;
144 my $res = "HTTP/1.1 $code $msg\015\012"; 153 my $res = "HTTP/1.1 $code $msg\015\012";
145 154
146 #$res .= "Connection: close\015\012"; 155 $self->{h}{connection} ||= $hdr->{Connection};
156
147 $res .= "Date: ".(time2str $::NOW)."\015\012"; # slow? nah. :( 157 $res .= "Date: ".(time2str $::NOW)."\015\012"; # slow? nah. :(
148 158
149 while (my ($h, $v) = each %$hdr) { 159 while (my ($h, $v) = each %$hdr) {
150 $res .= "$h: $v\015\012" 160 $res .= "$h: $v\015\012"
151 } 161 }
152 $res .= "\015\012"; 162 $res .= "\015\012";
153 163
154 $res .= $content if defined $content and $self->{method} ne "HEAD"; 164 $res .= $content if defined $content and $self->{method} ne "HEAD";
155 165
156 print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n"; 166 my $log = "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";
167
168 print $accesslog $log if $accesslog;
169 print STDERR $log;
157 170
158 $self->{written} += 171 $self->{written} +=
159 print {$self->{fh}} $res; 172 print {$self->{fh}} $res;
160} 173}
161 174
186 { 199 {
187 "Content-Type" => "text/html", 200 "Content-Type" => "text/html",
188 "Retry-After" => $::BLOCKTIME, 201 "Retry-After" => $::BLOCKTIME,
189 "Warning" => "Please do NOT retry, you have been blocked", 202 "Warning" => "Please do NOT retry, you have been blocked",
190 "WWW-Authenticate" => "Basic realm=\"Please do NOT retry, you have been blocked\"", 203 "WWW-Authenticate" => "Basic realm=\"Please do NOT retry, you have been blocked\"",
204 "Connection" => "close",
191 }, 205 },
192 <<EOF); 206 <<EOF);
193<html><p> 207<html>
208<head>
209<title>Too many connections</title>
210</head>
211<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000">
212
194You have been blocked because you opened too many connections. You 213<p>You have been blocked because you opened too many connections. You
195may retry at</p> 214may retry at</p>
196 215
197 <p><blockquote>$time.</blockquote></p> 216 <p><blockquote>$time.</blockquote></p>
198 217
199<p>Until then, each new access will renew the block. You might want to have a 218<p>Until then, each new access will renew the block. You might want to have a
200look at the <a href="http://www.goof.com/pcg/marc/animefaq.html">FAQ</a>.</p> 219look at the <a href="http://www.goof.com/pcg/marc/animefaq.html#connectionlimit">FAQ</a>.</p>
201</html> 220
221</body></html>
202EOF 222EOF
203} 223}
204 224
205sub handle { 225sub handle {
206 my $self = shift; 226 my $self = shift;
441 461
442satisfiable: 462satisfiable:
443 # check for segmented downloads 463 # check for segmented downloads
444 if ($l && $::NO_SEGMENTED) { 464 if ($l && $::NO_SEGMENTED) {
445 if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) { 465 if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) {
446 $self->err(400, "segmented downloads are not allowed"); 466 $self->err(400, "segmented downloads are not allowed",
467 { "Content-Type" => "text/html", Connection => "close" }, <<EOF);
468<html>
469<head>
470<title>Segmented downloads are not allowed</title>
471</head>
472<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#000080" alink="#ff0000">
473
474<p>Segmented downloads are not allowed on this server. Please refer to the
475<a href="http://www.goof.com/pcg/marc/animefaq.html#segmented_downloads">FAQ</a>.</p>
476
477</body></html>
478EOF
479EOF
447 } 480 }
448 } 481 }
449 482
450 $hdr->{"Content-Range"} = "bytes $l-$h/$length"; 483 $hdr->{"Content-Range"} = "bytes $l-$h/$length";
451 @code = (206, "partial content"); 484 @code = (206, "partial content");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines