--- deliantra/server/ext/http.ext 2012/10/30 17:43:16 1.3 +++ deliantra/server/ext/http.ext 2012/10/30 18:36:42 1.4 @@ -31,53 +31,61 @@ sub handle_req { my ($self) = @_; - $self->{rbuf} =~ s/^( ( [^\015]+ | . )+? )\015\012\015\012//xs - or return; + while ($self->{rbuf} =~ s/^( ( [^\015]+ | . )+? )\015\012\015\012//xs) { + my $req = $1; - my $req = $1; + # we ignore headers atm. - # we ignore headers atm. + $req =~ s%^GET (\S+) HTTP/[0-9.]+\015\012%% + or return $self->fatal; - $req =~ s%^GET (\S+) HTTP/[0-9.]+\015\012%% - or return $self->fatal; + my $uri = $1; - my $uri = $1; + $uri =~ s%^http://[^/]*%%i; # just in case - $uri =~ s%^http://[^/]*%%i; # just in case + cf::debug "HTTP GET: $self->{id} $uri"; - cf::debug "HTTP GET: $self->{id} $uri"; + if ($uri =~ m%^/([0-9a-f]+)$%) { # faces + my $idx = $cf::FACEHASH{pack "H*", $1}; - if ($uri =~ m%^/([0-9a-f]+)$%) { # faces - my $idx = $cf::FACEHASH{pack "H*", $1}; + $idx + or return $self->respond ("404 illegal face name"); - $idx - or return $self->respond ("404 illegal face name"); + if ($req =~ /if-none-match/i) { # dirtiest hack evar + $self->respond ("304 not modified"); + return; + } - my $type = cf::face::get_type $idx, 1; + my $type = cf::face::get_type $idx, 1; - if ($type & 1) { - $self->respond ("404 type $type not served yet"); - } else { - if ($type == 0) { # faces - $self->respond ("200 OK", (cf::face::get_data $idx, 1), "Content-Type: image/png\015\012Cache-Control: max-age=864000\015\012"); - } else { + if ($type & 1) { $self->respond ("404 type $type not served yet"); + } else { + if ($type == 0) { # faces + $self->respond ("200 OK", (cf::face::get_data $idx, 1), + "content-type: image/png\015\012" + . "cache-control: max-age=864000\015\012" + . "etag: \"0\"\015\012" + ); + } else { + $self->respond ("404 type $type not served yet"); + } } - } - } elsif ($uri eq "/allimgs") { # for debugging - my $body = ""; + } elsif ($uri eq "/allimgs") { # for debugging + my $body = ""; - for (1 .. cf::face::faces_size - 1) { - next if cf::face::get_type $_; - my $name = cf::face::get_chksum $_, 1; - $body .= "
"; - } + for (1 .. cf::face::faces_size - 1) { + next if cf::face::get_type $_; + my $name = cf::face::get_chksum $_, 1; + $body .= "
"; + } - $body .= ""; + $body .= ""; - $self->respond ("200 OK", $body, "Content-Type: text/html\015\012"); - } else { - $self->respond ("404 not found"); + $self->respond ("200 OK", $body, "Content-Type: text/html\015\012"); + } else { + $self->respond ("404 not found"); + } } }