… | |
… | |
40 | } |
40 | } |
41 | |
41 | |
42 | my $cache_headers = "cache-control: max-age=8640000\015\012" |
42 | my $cache_headers = "cache-control: max-age=8640000\015\012" |
43 | . "etag: \"0\"\015\012"; |
43 | . "etag: \"0\"\015\012"; |
44 | |
44 | |
45 | sub content_type { |
45 | sub content_type($$) { |
46 | return "content-type: image/png\015\012" if $_[0] =~ /^\x89PNG/; |
46 | return "content-type: image/png\015\012" if $_[1] =~ /^\x89PNG/; |
47 | return "content-type: image/jpeg\015\012" if $_[0] =~ /^......JFIF/s; |
47 | return "content-type: image/jpeg\015\012" if $_[1] =~ /^......JFIF/s; |
48 | return "content-type: audio/wav\015\012" if $_[0] =~ /^RIFF/; |
48 | return "content-type: audio/wav\015\012" if $_[1] =~ /^RIFF/; |
49 | return "content-type: audio/ogg\015\012" if $_[0] =~ /^OggS/; |
49 | return "content-type: audio/ogg\015\012" if $_[1] =~ /^OggS/; |
50 | return "content-type: text/html\015\012" if $_[0] =~ /^</; |
50 | return "content-type: text/html\015\012" if $_[1] =~ /^</; |
|
|
51 | return "content-type: text/css\015\012" if $_[0] =~ /\.css$/; |
51 | |
52 | |
52 | "content-type: text/plain\015\012" |
53 | "content-type: text/plain\015\012" |
53 | } |
54 | } |
54 | |
55 | |
55 | sub handle_con { |
56 | sub handle_con { |
… | |
… | |
138 | $self->respond ("200 OK", $meta, "content-type: text/plain\015\012" . $cache_headers); |
139 | $self->respond ("200 OK", $meta, "content-type: text/plain\015\012" . $cache_headers); |
139 | } else { |
140 | } else { |
140 | $self->respond ("404 type $type has no metadata"); |
141 | $self->respond ("404 type $type has no metadata"); |
141 | } |
142 | } |
142 | } else { |
143 | } else { |
143 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
144 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $cache_headers); |
144 | } |
145 | } |
145 | |
146 | |
146 | } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { |
147 | } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { |
147 | # TODO: use etag (shudder) |
148 | # TODO: use etag (shudder) |
148 | my $data = cf::face::get_data $idx; |
149 | my $data = cf::face::get_data $idx; |
149 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
150 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $cache_headers); |
150 | |
151 | |
151 | } elsif (cf::face::find "res/http$uri/index.html") { |
152 | } elsif (cf::face::find "res/http$uri/index.html") { |
152 | $self->respond ("302 dirslash", "", "location: $uri/\015\012"); |
153 | $self->respond ("302 dirslash", "", "location: $uri/\015\012"); |
153 | |
154 | |
154 | } elsif ($uri eq "/debug") { # for debugging |
155 | } elsif ($uri eq "/debug") { # for debugging |