… | |
… | |
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 $_[1] =~ /^\x89PNG/; |
46 | return "content-type: image/png\015\012" if $_[1] =~ /^\x89PNG/; |
47 | return "content-type: image/jpeg\015\012" if $_[1] =~ /^......JFIF/s; |
47 | return "content-type: image/jpeg\015\012" if $_[1] =~ /^......JFIF/s; |
48 | return "content-type: audio/wav\015\012" if $_[1] =~ /^RIFF/; |
48 | return "content-type: audio/wav\015\012" if $_[1] =~ /^RIFF/; |
49 | return "content-type: audio/ogg\015\012" if $_[1] =~ /^OggS/; |
49 | return "content-type: audio/ogg\015\012" if $_[1] =~ /^OggS/; |
50 | return "content-type: text/html\015\012" if $_[1] =~ /^</; |
|
|
51 | return "content-type: text/css\015\012" if $_[0] =~ /\.css$/; |
50 | return "content-type: text/css; charset=utf-8\015\012" if $_[0] =~ /\.css$/; |
|
|
51 | return "content-type: application/javascript; charset=utf-8\015\012" if $_[0] =~ /\.js$/; |
|
|
52 | return "content-type: text/html; charset=utf-8\015\012" if $_[1] =~ /^</; |
52 | |
53 | |
53 | "content-type: text/plain\015\012" |
54 | "content-type: text/plain; charset=utf-8\015\012" |
54 | } |
55 | } |
55 | |
56 | |
56 | sub handle_con { |
57 | sub handle_con { |
57 | my ($self) = @_; |
58 | my ($self) = @_; |
58 | |
59 | |
… | |
… | |
134 | (my $meta, $data) = unpack "(w/a*)*", $data |
135 | (my $meta, $data) = unpack "(w/a*)*", $data |
135 | if $type & 1; |
136 | if $type & 1; |
136 | |
137 | |
137 | if ($want_meta) { |
138 | if ($want_meta) { |
138 | if ($type & 1) { |
139 | if ($type & 1) { |
139 | $self->respond ("200 OK", $meta, "content-type: text/plain\015\012" . $cache_headers); |
140 | $self->respond ("200 OK", $meta, "content-type: text/plain; charset=utf-8\015\012" . $cache_headers); |
140 | } else { |
141 | } else { |
141 | $self->respond ("404 type $type has no metadata"); |
142 | $self->respond ("404 type $type has no metadata"); |
142 | } |
143 | } |
143 | } else { |
144 | } else { |
144 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $cache_headers); |
145 | $self->respond ("200 OK", $data, (content_type $uri, $data) . $cache_headers); |
… | |
… | |
186 | |
187 | |
187 | push @body, "</body></html>"; |
188 | push @body, "</body></html>"; |
188 | |
189 | |
189 | my $body = join "", @body; |
190 | my $body = join "", @body; |
190 | utf8::encode $body; |
191 | utf8::encode $body; |
191 | $self->respond ("200 OK", $body, "content-type: text/html\015\012"); |
192 | $self->respond ("200 OK", $body, "content-type: text/html; charset=utf-8\015\012"); |
192 | |
193 | |
193 | } else { |
194 | } else { |
194 | $self->respond ("404 not found"); |
195 | $self->respond ("404 not found"); |
195 | } |
196 | } |
196 | |
197 | |