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.1 by root, Tue Oct 30 17:07:50 2012 UTC vs.
Revision 1.5 by root, Tue Oct 30 19:19:39 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 if ($uri =~ m%^/([0-9a-f]+)$%) { # faces 46 cf::debug "HTTP GET: $self->{id} $uri";
47 my $idx = $cf::FACEHASH{pack "H*", $1};
48 47
49 $idx 48 if ($uri =~ m%^/([0-9a-f]+)$%) { # faces
50 or return $self->respond ("404 illegal face name"); 49 my $idx = $cf::FACEHASH{pack "H*", $1};
51 50
52 my $type = cf::face::get_type $idx, 1; 51 $idx
52 or return $self->respond ("404 illegal face name");
53 53
54 if ($req =~ /if-none-match/i) { # dirtiest hack evar
55 $self->respond ("304 not modified");
56 return;
57 }
58
59 my $type = cf::face::get_type $idx, 1;
60
54 if ($type & 1) { 61 if ($type & 1) {
55 $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=8640000\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");
56 } else { 86 } else {
57 if ($type == 0) { # faces 87 $self->respond ("404 not found");
58 $self->respond ("200 OK", (cf::face::get_data $idx, 1), "Content-Type: image/png\015\012");
59 } else {
60 $self->respond ("404 type $type not served yet");
61 }
62 } 88 }
63 } else {
64 $self->respond ("404 not found");
65 } 89 }
66} 90}
67 91
68# dirty hack: called directly from tcp.ext 92# dirty hack: called directly from tcp.ext
69sub server { 93sub server {
70 my $self = bless { 94 my $self = bless {
95 id => $_[0],
71 fh => $_[0], 96 fh => $_[1],
72 rbuf => $_[1], 97 rbuf => $_[2],
73 wbuf => "", 98 wbuf => "",
74 }; 99 };
75 100
76 $self->{rw} = AE::io $self->{fh}, 0, sub { 101 $self->{rw} = AE::io $self->{fh}, 0, sub {
77 my $len = sysread $self->{fh}, $self->{rbuf}, 4096, length $self->{rbuf}; 102 my $len = sysread $self->{fh}, $self->{rbuf}, 4096, length $self->{rbuf};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines