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.12 by root, Sat Aug 11 23:10:56 2001 UTC vs.
Revision 1.15 by root, Tue Aug 14 02:28:51 2001 UTC

43 43
44my $http_port = new Coro::Socket 44my $http_port = new Coro::Socket
45 LocalAddr => $SERVER_HOST, 45 LocalAddr => $SERVER_HOST,
46 LocalPort => $SERVER_PORT, 46 LocalPort => $SERVER_PORT,
47 ReuseAddr => 1, 47 ReuseAddr => 1,
48 Listen => 1, 48 Listen => 50,
49 or die "unable to start server"; 49 or die "unable to start server";
50 50
51push @listen_sockets, $http_port; 51push @listen_sockets, $http_port;
52 52
53# the "main thread" 53# the "main thread"
104 $self->{time} = $::NOW; 104 $self->{time} = $::NOW;
105 105
106 # enter ourselves into various lists 106 # enter ourselves into various lists
107 weaken ($conn{$self->{remote_addr}}{$self*1} = $self); 107 weaken ($conn{$self->{remote_addr}}{$self*1} = $self);
108 108
109 $::conns++;
110
109 $self; 111 $self;
110} 112}
111 113
112sub DESTROY { 114sub DESTROY {
113 my $self = shift; 115 my $self = shift;
116
117 $::conns--;
118
114 delete $conn{$self->{remote_addr}}{$self*1}; 119 delete $conn{$self->{remote_addr}}{$self*1};
115 delete $uri{$self->{uri}}{$self*1}; 120 delete $uri{$self->{remote_addr}}{$self->{uri}}{$self*1};
116} 121}
117 122
118sub slog { 123sub slog {
119 my $self = shift; 124 my $self = shift;
120 main::slog($_[0], "$self->{remote_addr}> $_[1]"); 125 main::slog($_[0], "$self->{remote_addr}> $_[1]");
130 while (my ($h, $v) = each %$hdr) { 135 while (my ($h, $v) = each %$hdr) {
131 $res .= "$h: $v\015\012" 136 $res .= "$h: $v\015\012"
132 } 137 }
133 $res .= "\015\012"; 138 $res .= "\015\012";
134 139
135 $res .= $content if defined $content and $self->{method} eq "GET"; 140 $res .= $content if defined $content and $self->{method} ne "HEAD";
136 141
137 print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";#d# 142 print STDERR "$self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n";#d#
138 143
139 $self->{written} += 144 $self->{written} +=
140 print {$self->{fh}} $res; 145 print {$self->{fh}} $res;
158sub err_blocked { 163sub err_blocked {
159 my $self = shift; 164 my $self = shift;
160 my $ip = $self->{remote_addr}; 165 my $ip = $self->{remote_addr};
161 my $time = time2str $blocked{$ip} = $::NOW + $::BLOCKTIME; 166 my $time = time2str $blocked{$ip} = $::NOW + $::BLOCKTIME;
162 167
163 Coro::Event::do_timer(after => 5); 168 Coro::Event::do_timer(after => 15);
164 169
165 $self->err(403, "too many connections", 170 $self->err(401, "too many connections",
166 { 171 {
167 "Content-Type" => "text/html", 172 "Content-Type" => "text/html",
168 "Retry-After" => $::BLOCKTIME 173 "Retry-After" => $::BLOCKTIME
169 }, 174 },
170 <<EOF); 175 <<EOF);
212 $req =~ /^(?:\015\012)? 217 $req =~ /^(?:\015\012)?
213 (GET|HEAD) \040+ 218 (GET|HEAD) \040+
214 ([^\040]+) \040+ 219 ([^\040]+) \040+
215 HTTP\/([0-9]+\.[0-9]+) 220 HTTP\/([0-9]+\.[0-9]+)
216 \015\012/gx 221 \015\012/gx
217 or $self->err(403, "method not allowed", { Allow => "GET,HEAD" }); 222 or $self->err(405, "method not allowed", { Allow => "GET,HEAD" });
218 223
219 $2 ne "1.0" 224 $2 ne "1.0"
220 or $self->err(506, "http protocol version not supported"); 225 or $self->err(506, "http protocol version not supported");
221 226
222 $self->{method} = $1; 227 $self->{method} = $1;
241 while ($h, $v) = each %hdr; 246 while ($h, $v) = each %hdr;
242 } 247 }
243 248
244 $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80; 249 $self->{server_port} = $self->{h}{host} =~ s/:([0-9]+)$// ? $1 : 80;
245 250
246 weaken ($uri{$self->{uri}}{$self*1} = $self); 251 weaken ($uri{$self->{remote_addr}}{$self->{uri}}{$self*1} = $self);
247 252
248 $self->map_uri; 253 $self->map_uri;
249 $self->respond; 254 $self->respond;
250 #} 255 #}
251} 256}
399 $self->err(416, "not satisfiable", $hdr); 404 $self->err(416, "not satisfiable", $hdr);
400 405
401satisfiable: 406satisfiable:
402 # check for segmented downloads 407 # check for segmented downloads
403 if ($l && $::NO_SEGMENTED) { 408 if ($l && $::NO_SEGMENTED) {
404 if (%{$uri{$self->{uri}}} > 1) { 409 if (%{$uri{$self->{remote_addr}}{$self->{uri}}} > 1) {
410 Coro::Event::do_timer(after => 15);
411
405 $self->err(400, "segmented downloads are not allowed"); 412 $self->err(400, "segmented downloads are not allowed");
406 } 413 }
407 } 414 }
408 415
409 $hdr->{"Content-Range"} = "bytes $l-$h/$length"; 416 $hdr->{"Content-Range"} = "bytes $l-$h/$length";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines