… | |
… | |
37 | . "access-control-allow-origin: *\015\012" |
37 | . "access-control-allow-origin: *\015\012" |
38 | . $_[0]{ohdr} |
38 | . $_[0]{ohdr} |
39 | . "$_[3]\015\012" . ($_[0]{give_head} ? "" : $_[2])); |
39 | . "$_[3]\015\012" . ($_[0]{give_head} ? "" : $_[2])); |
40 | } |
40 | } |
41 | |
41 | |
42 | my $cache_headers = "cache-control: max-age=8640000\015\012" |
42 | my $cache_headers = "cache-control: public, max-age=8640000\015\012" |
43 | . "etag: \"0\"\015\012"; |
43 | . "etag: \"0\"\015\012"; |
|
|
44 | |
|
|
45 | my $revalidate_headers = "cache-control: public, max-age=60, must-revalidate\015\012"; |
|
|
46 | |
|
|
47 | my $nocache_headers = "cache-control: no-cache, max-age=0\015\012"; |
44 | |
48 | |
45 | sub content_type($$) { |
49 | sub content_type($$) { |
46 | return "content-type: image/png\015\012" if $_[1] =~ /^\x89PNG/; |
50 | return "content-type: image/png\015\012" if $_[1] =~ /^\x89PNG/; |
47 | return "content-type: image/jpeg\015\012" if $_[1] =~ /^......JFIF/s; |
51 | return "content-type: image/jpeg\015\012" if $_[1] =~ /^......JFIF/s; |
48 | return "content-type: audio/wav\015\012" if $_[1] =~ /^RIFF/; |
52 | return "content-type: audio/wav\015\012" if $_[1] =~ /^RIFF/; |
… | |
… | |
144 | } else { |
148 | } else { |
145 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $cache_headers); |
149 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $cache_headers); |
146 | } |
150 | } |
147 | |
151 | |
148 | } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { |
152 | } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { |
149 | # TODO: use etag (shudder) |
|
|
150 | my $data = cf::face::get_data $idx; |
153 | my $data = cf::face::get_data $idx; |
|
|
154 | my $csum = unpack "H*", cf::face::get_csum $idx; |
|
|
155 | my $hdr = "etag: \"$csum\"\015\012" . $revalidate_headers; |
|
|
156 | |
|
|
157 | if ($req =~ /if-none-match: "$csum"/i) { # dirtiest hack evar |
|
|
158 | $self->respond ("304 not modified", "", $hdr); |
|
|
159 | next; |
|
|
160 | } |
|
|
161 | |
151 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $cache_headers); |
162 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $hdr); |
152 | |
163 | |
153 | } elsif (cf::face::find "res/http$uri/index.html") { |
164 | } elsif (cf::face::find "res/http$uri/index.html") { |
154 | $self->respond ("302 dirslash", "", "location: $uri/\015\012"); |
165 | $self->respond ("302 dirslash", "", "location: $uri/\015\012" . $nocache_headers); |
155 | |
166 | |
156 | } elsif ($uri eq "/debug") { # for debugging |
167 | } elsif ($uri eq "/debug") { # for debugging |
157 | my @body = <<EOF; |
168 | my @body = <<EOF; |
158 | <html><head><style> |
169 | <html><head><style> |
159 | th:nth-child(1) { text-align: right; } |
170 | th:nth-child(1) { text-align: right; } |