--- deliantra/server/ext/tcp_http.ext 2012/11/06 21:50:36 1.3 +++ deliantra/server/ext/tcp_http.ext 2012/11/09 00:11:49 1.8 @@ -26,6 +26,7 @@ $_[0]->send ("HTTP/1.1 $_[1]\015\012" . "content-length: " . (0 + length $_[2]) . "\015\012" . "access-control-allow-origin: *\015\012" + . $_[0]{ohdr} . "$_[3]\015\012$_[2]"); } @@ -37,6 +38,7 @@ return "content-type: image/jpeg\015\012" if $_[0] =~ /^......JFIF/s; return "content-type: audio/wav\015\012" if $_[0] =~ /^RIFF/; return "content-type: audio/ogg\015\012" if $_[0] =~ /^OggS/; + return "content-type: text/html\015\012" if $_[0] =~ /^fatal; - my $uri = $1; + my $uri = $1; + my $http = $2; + + if ($http == 1.0) { + if ($req =~ /^connection\s*:\s*keep-alive/mi) { + $self->{ohdr} = "connection: keep-alive\015\012"; + } else { + $self->{ohdr} = "connection: close\015\012"; + delete $self->{rw}; + } + } $uri =~ s%^http://[^/]*%%i; # just in case cf::debug "HTTP GET: $self->{id} $uri"; if ($uri =~ m%^/([0-9a-f]+)(M?)$%) { # faces - my $want_meta = $1; - my $idx = $cf::FACEHASH{pack "H*", $2}; + my $want_meta = $2; + my $idx = $cf::FACEHASH{pack "H*", $1}; $idx or do { $self->respond ("404 illegal face name"), next }; @@ -86,6 +98,14 @@ $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); } + } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { + # TODO: temp redirect to face itself, for caching, or use etag (shudder) + my $data = cf::face::get_data $idx, 1; + $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); + + } elsif (cf::face::find "res/http$uri/index.html") { + $self->respond ("302 dirslash", "", "location: $uri/\015\012"); + } elsif ($uri eq "/debug") { # for debugging my @body = ""; @@ -104,7 +124,7 @@ push @body, ""; - $self->respond ("200 OK", (join "", @body), "Content-Type: text/html\015\012"); + $self->respond ("200 OK", (join "", @body), "content-type: text/html\015\012"); } elsif ($uri eq "/ws" && defined &ext::ws::server) { &ext::ws::server ($self->{id}, $self->{fh}, "$req\015\012\015\012$self->{rbuf}");