… | |
… | |
150 | my $peername = shift; |
150 | my $peername = shift; |
151 | my $self = bless { fh => $fh }, $class; |
151 | my $self = bless { fh => $fh }, $class; |
152 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
152 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
153 | or $self->err(500, "unable to decode peername"); |
153 | or $self->err(500, "unable to decode peername"); |
154 | |
154 | |
|
|
155 | $self->{remote_addr} = |
155 | $self->{remote_addr} = inet_ntoa $iaddr; |
156 | $self->{remote_id} = inet_ntoa $iaddr; |
156 | $self->{time} = $::NOW; |
157 | $self->{time} = $::NOW; |
157 | |
158 | |
158 | weaken ($Coro::current->{conn} = $self); |
159 | weaken ($Coro::current->{conn} = $self); |
159 | |
160 | |
160 | $::conns++; |
161 | $::conns++; |
… | |
… | |
179 | $httpevent->broadcast; |
180 | $httpevent->broadcast; |
180 | } |
181 | } |
181 | |
182 | |
182 | sub slog { |
183 | sub slog { |
183 | my $self = shift; |
184 | my $self = shift; |
184 | main::slog($_[0], ($self->{remote_id} || $self->{remote_addr}) ."> $_[1]"); |
185 | main::slog($_[0], "$self->{remote_id}> $_[1]"); |
185 | } |
186 | } |
186 | |
187 | |
187 | sub response { |
188 | sub response { |
188 | my ($self, $code, $msg, $hdr, $content) = @_; |
189 | my ($self, $code, $msg, $hdr, $content) = @_; |
189 | my $res = "HTTP/1.1 $code $msg\015\012"; |
190 | my $res = "HTTP/1.1 $code $msg\015\012"; |
… | |
… | |
210 | $res .= "\015\012"; |
211 | $res .= "\015\012"; |
211 | |
212 | |
212 | $res .= $content if defined $content and $self->{method} ne "HEAD"; |
213 | $res .= $content if defined $content and $self->{method} ne "HEAD"; |
213 | |
214 | |
214 | my $log = (POSIX::strftime "%Y-%m-%d %H:%M:%S", gmtime $NOW). |
215 | my $log = (POSIX::strftime "%Y-%m-%d %H:%M:%S", gmtime $NOW). |
215 | " $self->{remote_addr} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}." \"$self->{h}{referer}\"\n"; |
216 | " $self->{remote_id} \"$self->{uri}\" $code ".$hdr->{"Content-Length"}. |
|
|
217 | " \"$self->{h}{referer}\"\n"; |
216 | |
218 | |
217 | print $accesslog $log if $accesslog; |
219 | print $accesslog $log if $accesslog; |
218 | print STDERR $log; |
220 | print STDERR $log; |
219 | |
221 | |
220 | $self->{written} += |
222 | $self->{written} += |
… | |
… | |
468 | |
470 | |
469 | $self->response(200, "ok", |
471 | $self->response(200, "ok", |
470 | { |
472 | { |
471 | "Content-Type" => "text/html", |
473 | "Content-Type" => "text/html", |
472 | "Content-Length" => length $idx, |
474 | "Content-Length" => length $idx, |
|
|
475 | #d# directories change all the time, so X- |
473 | "Last-Modified" => time2str ((stat _)[9]), |
476 | "X-Last-Modified" => time2str ((stat _)[9]), |
474 | }, |
477 | }, |
475 | $idx); |
478 | $idx); |
476 | } |
479 | } |
477 | |
480 | |
478 | sub handle_file { |
481 | sub handle_file { |