… | |
… | |
23 | $self->send ("HTTP/1.1 500 internal error\015\012"); |
23 | $self->send ("HTTP/1.1 500 internal error\015\012"); |
24 | delete $self->{rw}; |
24 | delete $self->{rw}; |
25 | } |
25 | } |
26 | |
26 | |
27 | sub respond { |
27 | sub respond { |
28 | $_[0]->send ("HTTP/1.1 $_[1]\015\012Content-Length: " . (0 + length $_[2]) . "\015\012$_[3]\015\012$_[2]"); |
28 | $_[0]->send ("HTTP/1.1 $_[1]\015\012content-length: " . (0 + length $_[2]) . "\015\012$_[3]\015\012$_[2]"); |
29 | } |
29 | } |
|
|
30 | |
|
|
31 | my $cache_headers = "cache-control: max-age=8640000\015\012" |
|
|
32 | . "etag: \"0\"\015\012"; |
30 | |
33 | |
31 | sub handle_req { |
34 | sub handle_req { |
32 | my ($self) = @_; |
35 | my ($self) = @_; |
33 | |
36 | |
34 | while ($self->{rbuf} =~ s/^( ( [^\015]+ | . )+? )\015\012\015\012//xs) { |
37 | while ($self->{rbuf} =~ s/^( ( [^\015]+ | . )+? )\015\012\015\012//xs) { |
… | |
… | |
50 | |
53 | |
51 | $idx |
54 | $idx |
52 | or return $self->respond ("404 illegal face name"); |
55 | or return $self->respond ("404 illegal face name"); |
53 | |
56 | |
54 | if ($req =~ /if-none-match/i) { # dirtiest hack evar |
57 | if ($req =~ /if-none-match/i) { # dirtiest hack evar |
55 | $self->respond ("304 not modified"); |
58 | $self->respond ("304 not modified", "", $cache_headers); |
56 | return; |
59 | return; |
57 | } |
60 | } |
58 | |
61 | |
59 | my $type = cf::face::get_type $idx, 1; |
62 | my $type = cf::face::get_type $idx, 1; |
60 | |
63 | |
61 | if ($type & 1) { |
64 | if ($type & 1) { |
62 | $self->respond ("404 type $type not served yet"); |
65 | $self->respond ("404 type $type not served yet"); |
63 | } else { |
66 | } else { |
64 | if ($type == 0) { # faces |
67 | if ($type == 0) { # faces |
65 | $self->respond ("200 OK", (cf::face::get_data $idx, 1), |
68 | $self->respond ("200 OK", (cf::face::get_data $idx, 1), "content-type: image/png\015\012$cache_headers"); |
66 | "content-type: image/png\015\012" |
|
|
67 | . "cache-control: max-age=8640000\015\012" |
|
|
68 | . "etag: \"0\"\015\012" |
|
|
69 | ); |
|
|
70 | } else { |
69 | } else { |
71 | $self->respond ("404 type $type not served yet"); |
70 | $self->respond ("404 type $type not served yet"); |
72 | } |
71 | } |
73 | } |
72 | } |
74 | } elsif ($uri eq "/allimgs") { # for debugging |
73 | } elsif ($uri eq "/allimgs") { # for debugging |