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

Comparing cvsroot/Coro/myhttpd/httpd.pl (file contents):
Revision 1.61 by root, Thu Jan 3 01:20:17 2002 UTC vs.
Revision 1.65 by root, Fri Jan 25 09:26:13 2002 UTC

4use Coro::Socket; 4use Coro::Socket;
5use Coro::Signal; 5use Coro::Signal;
6 6
7use HTTP::Date; 7use HTTP::Date;
8use POSIX (); 8use POSIX ();
9
10use Compress::Zlib ();
9 11
10no utf8; 12no utf8;
11use bytes; 13use bytes;
12 14
13# at least on my machine, this thingy serves files 15# at least on my machine, this thingy serves files
50} 52}
51 53
52our $connections = new Coro::Semaphore $MAX_CONNECTS || 250; 54our $connections = new Coro::Semaphore $MAX_CONNECTS || 250;
53our $httpevent = new Coro::Signal; 55our $httpevent = new Coro::Signal;
54 56
55our $queue_file = new transferqueue slots => $MAX_TRANSFERS, maxsize => 256*1024*1024; 57our $queue_file = new transferqueue $MAX_TRANSFERS;
56our $queue_index = new transferqueue slots => 10; 58our $queue_index = new transferqueue 10;
57 59
58my @newcons; 60my @newcons;
59my @pool; 61my @pool;
60 62
61# one "execution thread" 63# one "execution thread"
185} 187}
186 188
187sub response { 189sub response {
188 my ($self, $code, $msg, $hdr, $content) = @_; 190 my ($self, $code, $msg, $hdr, $content) = @_;
189 my $res = "HTTP/1.1 $code $msg\015\012"; 191 my $res = "HTTP/1.1 $code $msg\015\012";
192 my $GZ = "";
190 193
191 if (exists $hdr->{Connection}) { 194 if (exists $hdr->{Connection}) {
192 if ($hdr->{Connection} =~ /close/) { 195 if ($hdr->{Connection} =~ /close/) {
193 $self->{h}{connection} = "close" 196 $self->{h}{connection} = "close"
194 } 197 }
200 $self->{h}{connection} = "close" 203 $self->{h}{connection} = "close"
201 } 204 }
202 } 205 }
203 } 206 }
204 207
208 if ($self->{method} ne "HEAD"
209 && $self->{h}{"accept-encoding"} =~ /\bgzip\b/
210 && 400 < length $content
211 && $hdr->{"Content-Length"} == length $content
212 && !exists $hdr->{"Content-Encoding"}
213 ) {
214 my $orig = length $content;
215 $hdr->{"Content-Encoding"} = "gzip";
216 $content = Compress::Zlib::memGzip(\$content);
217 $hdr->{"Content-Length"} = length $content;
218 $GZ = sprintf "GZ%02d", 100 - 100*((length $content) / $orig);
219 }
220
205 $res .= "Date: $HTTP_NOW\015\012"; 221 $res .= "Date: $HTTP_NOW\015\012";
206 222
207 while (my ($h, $v) = each %$hdr) { 223 while (my ($h, $v) = each %$hdr) {
208 $res .= "$h: $v\015\012" 224 $res .= "$h: $v\015\012"
209 } 225 }
210 $res .= "\015\012"; 226 $res .= "\015\012";
211 227
212 $res .= $content if defined $content and $self->{method} ne "HEAD"; 228 $res .= $content if defined $content and $self->{method} ne "HEAD";
213 229
214 my $log = (POSIX::strftime "%Y-%m-%d %H:%M:%S", gmtime $NOW). 230 my $log = (POSIX::strftime "%Y-%m-%d %H:%M:%S", gmtime $::NOW).
215 " $self->{remote_id} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}. 231 " $self->{remote_id} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}.$GZ.
216 " \"$self->{h}{referer}\"\n"; 232 " \"$self->{h}{referer}\"\n";
217 233
218 print $accesslog $log if $accesslog; 234 print $::accesslog $log if $::accesslog;
219 print STDERR $log; 235 print STDERR $log;
220 236
221 $self->{written} += 237 $self->{written} +=
222 print {$self->{fh}} $res; 238 print {$self->{fh}} $res;
223} 239}
282 my (%hdr, $h, $v); 298 my (%hdr, $h, $v);
283 299
284 $hdr{lc $1} .= ",$2" 300 $hdr{lc $1} .= ",$2"
285 while $req =~ /\G 301 while $req =~ /\G
286 ([^:\000-\040]+): 302 ([^:\000-\040]+):
287 [\008\040]* 303 [\010\040]*
288 ((?: [^\015\012]+ | \015\012[\008\040] )*) 304 ((?: [^\015\012]+ | \015\012[\010\040] )*)
289 \015\012 305 \015\012
290 /gxc; 306 /gxc;
291 307
292 $req =~ /\G\015\012$/ 308 $req =~ /\G\015\012$/
293 or $self->err(400, "bad request"); 309 or $self->err(400, "bad request");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines