… | |
… | |
36 | sub content_type { |
36 | sub content_type { |
37 | return "content-type: image/png\015\012" if $_[0] =~ /^\x89PNG/; |
37 | return "content-type: image/png\015\012" if $_[0] =~ /^\x89PNG/; |
38 | return "content-type: image/jpeg\015\012" if $_[0] =~ /^......JFIF/s; |
38 | return "content-type: image/jpeg\015\012" if $_[0] =~ /^......JFIF/s; |
39 | return "content-type: audio/wav\015\012" if $_[0] =~ /^RIFF/; |
39 | return "content-type: audio/wav\015\012" if $_[0] =~ /^RIFF/; |
40 | return "content-type: audio/ogg\015\012" if $_[0] =~ /^OggS/; |
40 | return "content-type: audio/ogg\015\012" if $_[0] =~ /^OggS/; |
|
|
41 | return "content-type: text/html\015\012" if $_[0] =~ /^</; |
41 | |
42 | |
42 | "content-type: text/plain\015\012" |
43 | "content-type: text/plain\015\012" |
43 | } |
44 | } |
44 | |
45 | |
45 | sub handle_req { |
46 | sub handle_req { |
… | |
… | |
95 | } |
96 | } |
96 | } else { |
97 | } else { |
97 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
98 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
98 | } |
99 | } |
99 | |
100 | |
|
|
101 | } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { |
|
|
102 | my $data = cf::face::get_data $idx, 1; |
|
|
103 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
|
|
104 | |
|
|
105 | } elsif (cf::face::find "res/http$uri/index.html") { |
|
|
106 | $self->respond ("302 dirslash", "", "location: $uri/\015\012"); |
|
|
107 | |
100 | } elsif ($uri eq "/debug") { # for debugging |
108 | } elsif ($uri eq "/debug") { # for debugging |
101 | my @body = "<html><body>"; |
109 | my @body = "<html><body>"; |
102 | |
110 | |
103 | for my $type (6, 5, 4, 3, 2, 1, 0) { |
111 | for my $type (6, 5, 4, 3, 2, 1, 0) { |
104 | push @body, "<h1>$type</h1>"; |
112 | push @body, "<h1>$type</h1>"; |
… | |
… | |
118 | $self->respond ("200 OK", (join "", @body), "content-type: text/html\015\012"); |
126 | $self->respond ("200 OK", (join "", @body), "content-type: text/html\015\012"); |
119 | } elsif ($uri eq "/ws" && defined &ext::ws::server) { |
127 | } elsif ($uri eq "/ws" && defined &ext::ws::server) { |
120 | &ext::ws::server ($self->{id}, $self->{fh}, "$req\015\012\015\012$self->{rbuf}"); |
128 | &ext::ws::server ($self->{id}, $self->{fh}, "$req\015\012\015\012$self->{rbuf}"); |
121 | |
129 | |
122 | %$self = (); |
130 | %$self = (); |
123 | |
|
|
124 | } elsif ($uri eq "/") { |
|
|
125 | $self->respond ("302 hack", "", "location: http://cvs.schmorp.de/deliantra/html5client/client.html\015\012"); |
|
|
126 | |
131 | |
127 | } else { |
132 | } else { |
128 | $self->respond ("404 not found"); |
133 | $self->respond ("404 not found"); |
129 | } |
134 | } |
130 | } |
135 | } |