ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/http.ext
(Generate patch)

Comparing deliantra/server/ext/http.ext (file contents):
Revision 1.3 by root, Tue Oct 30 17:43:16 2012 UTC vs.
Revision 1.4 by root, Tue Oct 30 18:36:42 2012 UTC

29} 29}
30 30
31sub handle_req { 31sub handle_req {
32 my ($self) = @_; 32 my ($self) = @_;
33 33
34 $self->{rbuf} =~ s/^( ( [^\015]+ | . )+? )\015\012\015\012//xs 34 while ($self->{rbuf} =~ s/^( ( [^\015]+ | . )+? )\015\012\015\012//xs) {
35 or return; 35 my $req = $1;
36 36
37 my $req = $1; 37 # we ignore headers atm.
38 38
39 # we ignore headers atm. 39 $req =~ s%^GET (\S+) HTTP/[0-9.]+\015\012%%
40 or return $self->fatal;
40 41
41 $req =~ s%^GET (\S+) HTTP/[0-9.]+\015\012%% 42 my $uri = $1;
42 or return $self->fatal;
43 43
44 my $uri = $1; 44 $uri =~ s%^http://[^/]*%%i; # just in case
45 45
46 $uri =~ s%^http://[^/]*%%i; # just in case 46 cf::debug "HTTP GET: $self->{id} $uri";
47 47
48 cf::debug "HTTP GET: $self->{id} $uri"; 48 if ($uri =~ m%^/([0-9a-f]+)$%) { # faces
49 my $idx = $cf::FACEHASH{pack "H*", $1};
49 50
50 if ($uri =~ m%^/([0-9a-f]+)$%) { # faces 51 $idx
51 my $idx = $cf::FACEHASH{pack "H*", $1}; 52 or return $self->respond ("404 illegal face name");
52 53
53 $idx 54 if ($req =~ /if-none-match/i) { # dirtiest hack evar
54 or return $self->respond ("404 illegal face name"); 55 $self->respond ("304 not modified");
56 return;
57 }
55 58
56 my $type = cf::face::get_type $idx, 1; 59 my $type = cf::face::get_type $idx, 1;
57 60
58 if ($type & 1) { 61 if ($type & 1) {
59 $self->respond ("404 type $type not served yet"); 62 $self->respond ("404 type $type not served yet");
63 } else {
64 if ($type == 0) { # faces
65 $self->respond ("200 OK", (cf::face::get_data $idx, 1),
66 "content-type: image/png\015\012"
67 . "cache-control: max-age=864000\015\012"
68 . "etag: \"0\"\015\012"
69 );
70 } else {
71 $self->respond ("404 type $type not served yet");
72 }
73 }
74 } elsif ($uri eq "/allimgs") { # for debugging
75 my $body = "<html><body>";
76
77 for (1 .. cf::face::faces_size - 1) {
78 next if cf::face::get_type $_;
79 my $name = cf::face::get_chksum $_, 1;
80 $body .= "<img src='" . (unpack "H*", $name) . "'><br>";
81 }
82
83 $body .= "</body></html>";
84
85 $self->respond ("200 OK", $body, "Content-Type: text/html\015\012");
60 } else { 86 } else {
61 if ($type == 0) { # faces 87 $self->respond ("404 not found");
62 $self->respond ("200 OK", (cf::face::get_data $idx, 1), "Content-Type: image/png\015\012Cache-Control: max-age=864000\015\012");
63 } else {
64 $self->respond ("404 type $type not served yet");
65 }
66 } 88 }
67 } elsif ($uri eq "/allimgs") { # for debugging
68 my $body = "<html><body>";
69
70 for (1 .. cf::face::faces_size - 1) {
71 next if cf::face::get_type $_;
72 my $name = cf::face::get_chksum $_, 1;
73 $body .= "<img src='" . (unpack "H*", $name) . "'><br>";
74 }
75
76 $body .= "</body></html>";
77
78 $self->respond ("200 OK", $body, "Content-Type: text/html\015\012");
79 } else {
80 $self->respond ("404 not found");
81 } 89 }
82} 90}
83 91
84# dirty hack: called directly from tcp.ext 92# dirty hack: called directly from tcp.ext
85sub server { 93sub server {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines