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.2 by root, Tue Oct 30 17:32:47 2012 UTC

41 $req =~ s%^GET (\S+) HTTP/[0-9.]+\015\012%% 41 $req =~ s%^GET (\S+) HTTP/[0-9.]+\015\012%%
42 or return $self->fatal; 42 or return $self->fatal;
43 43
44 my $uri = $1; 44 my $uri = $1;
45 45
46 $uri =~ s%^http://[^/]*%%i; # just in case
47
48 cf::debug "HTTP GET: $self->{id} $uri";
49
46 if ($uri =~ m%^/([0-9a-f]+)$%) { # faces 50 if ($uri =~ m%^/([0-9a-f]+)$%) { # faces
47 my $idx = $cf::FACEHASH{pack "H*", $1}; 51 my $idx = $cf::FACEHASH{pack "H*", $1};
48 52
49 $idx 53 $idx
50 or return $self->respond ("404 illegal face name"); 54 or return $self->respond ("404 illegal face name");
58 $self->respond ("200 OK", (cf::face::get_data $idx, 1), "Content-Type: image/png\015\012"); 62 $self->respond ("200 OK", (cf::face::get_data $idx, 1), "Content-Type: image/png\015\012");
59 } else { 63 } else {
60 $self->respond ("404 type $type not served yet"); 64 $self->respond ("404 type $type not served yet");
61 } 65 }
62 } 66 }
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");
63 } else { 79 } else {
64 $self->respond ("404 not found"); 80 $self->respond ("404 not found");
65 } 81 }
66} 82}
67 83
68# dirty hack: called directly from tcp.ext 84# dirty hack: called directly from tcp.ext
69sub server { 85sub server {
70 my $self = bless { 86 my $self = bless {
87 id => $_[0],
71 fh => $_[0], 88 fh => $_[1],
72 rbuf => $_[1], 89 rbuf => $_[2],
73 wbuf => "", 90 wbuf => "",
74 }; 91 };
75 92
76 $self->{rw} = AE::io $self->{fh}, 0, sub { 93 $self->{rw} = AE::io $self->{fh}, 0, sub {
77 my $len = sysread $self->{fh}, $self->{rbuf}, 4096, length $self->{rbuf}; 94 my $len = sysread $self->{fh}, $self->{rbuf}, 4096, length $self->{rbuf};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines