… | |
… | |
141 | |
141 | |
142 | read_mimetypes; |
142 | read_mimetypes; |
143 | |
143 | |
144 | sub new { |
144 | sub new { |
145 | my $class = shift; |
145 | my $class = shift; |
|
|
146 | my $fh = shift; |
146 | my $peername = shift; |
147 | my $peername = shift; |
147 | my $fh = shift; |
|
|
148 | my $self = bless { fh => $fh }, $class; |
148 | my $self = bless { fh => $fh }, $class; |
149 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
149 | my (undef, $iaddr) = unpack_sockaddr_in $peername |
150 | or $self->err(500, "unable to decode peername"); |
150 | or $self->err(500, "unable to decode peername"); |
151 | |
151 | |
152 | $self->{remote_addr} = inet_ntoa $iaddr; |
152 | $self->{remote_addr} = inet_ntoa $iaddr; |
… | |
… | |
179 | |
179 | |
180 | sub response { |
180 | sub response { |
181 | my ($self, $code, $msg, $hdr, $content) = @_; |
181 | my ($self, $code, $msg, $hdr, $content) = @_; |
182 | my $res = "HTTP/1.1 $code $msg\015\012"; |
182 | my $res = "HTTP/1.1 $code $msg\015\012"; |
183 | |
183 | |
184 | $self->{h}{connection} ||= $hdr->{Connection}; |
184 | $self->{h}{connection} = "close" if $hdr->{Connection} =~ /close/; |
185 | |
185 | |
186 | $res .= "Date: $HTTP_NOW\015\012"; |
186 | $res .= "Date: $HTTP_NOW\015\012"; |
187 | |
187 | |
188 | while (my ($h, $v) = each %$hdr) { |
188 | while (my ($h, $v) = each %$hdr) { |
189 | $res .= "$h: $v\015\012" |
189 | $res .= "$h: $v\015\012" |