… | |
… | |
17 | |
17 | |
18 | $self->{ww} = AE::io $self->{fh}, 1, sub { |
18 | $self->{ww} = AE::io $self->{fh}, 1, sub { |
19 | my $len = syswrite $self->{fh}, $self->{wbuf}; |
19 | my $len = syswrite $self->{fh}, $self->{wbuf}; |
20 | substr $self->{wbuf}, 0, $len, ""; |
20 | substr $self->{wbuf}, 0, $len, ""; |
21 | |
21 | |
|
|
22 | delete $self->{ww} unless $len; # in case of errors, stop |
22 | $self->{ww}->stop unless length $self->{wbuf}; |
23 | delete $self->{ww} unless length $self->{wbuf}; |
23 | } if length $self->{wbuf}; |
24 | } if length $self->{wbuf}; |
24 | } |
25 | } |
25 | } |
26 | } |
26 | |
27 | |
27 | sub fatal { |
28 | sub fatal { |
… | |
… | |
112 | $self->send ("HTTP/1.1 100 go on\015\012") |
113 | $self->send ("HTTP/1.1 100 go on\015\012") |
113 | if $req =~ /^expect:.*\b100-continue\b/i; |
114 | if $req =~ /^expect:.*\b100-continue\b/i; |
114 | |
115 | |
115 | if ($uri =~ m%^/([0-9a-f]+)(M?)$%) { # faces |
116 | if ($uri =~ m%^/([0-9a-f]+)(M?)$%) { # faces |
116 | my $want_meta = $2; |
117 | my $want_meta = $2; |
117 | my $idx = $cf::FACEHASH{pack "H*", $1}; |
118 | my $idx = $cf::face::HASH{pack "H*", $1}; |
118 | |
119 | |
119 | $idx |
120 | $idx |
120 | or do { $self->respond ("404 illegal face name"), next }; |
121 | or do { $self->respond ("404 illegal face name"), next }; |
121 | |
122 | |
122 | if ($req =~ /if-none-match/i) { # dirtiest hack evar |
123 | if ($req =~ /if-none-match/i) { # dirtiest hack evar |
123 | $self->respond ("304 not modified", "", $cache_headers); |
124 | $self->respond ("304 not modified", "", $cache_headers); |
124 | next; |
125 | next; |
125 | } |
126 | } |
126 | |
127 | |
127 | my $type = cf::face::get_type $idx, 1; |
128 | my $type = cf::face::get_type $idx; |
128 | my $data = cf::face::get_data $idx, 1; |
129 | my $data = cf::face::get_data $idx; |
129 | |
130 | |
130 | (my $meta, $data) = unpack "(w/a*)*", $data |
131 | (my $meta, $data) = unpack "(w/a*)*", $data |
131 | if $type & 1; |
132 | if $type & 1; |
132 | |
133 | |
133 | if ($want_meta) { |
134 | if ($want_meta) { |
… | |
… | |
140 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
141 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
141 | } |
142 | } |
142 | |
143 | |
143 | } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { |
144 | } elsif (my $idx = (cf::face::find "res/http$uri") || (cf::face::find "res/http${uri}index.html")) { |
144 | # TODO: use etag (shudder) |
145 | # TODO: use etag (shudder) |
145 | my $data = cf::face::get_data $idx, 1; |
146 | my $data = cf::face::get_data $idx; |
146 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
147 | $self->respond ("200 OK", $data, (content_type $data) . $cache_headers); |
147 | |
148 | |
148 | } elsif (cf::face::find "res/http$uri/index.html") { |
149 | } elsif (cf::face::find "res/http$uri/index.html") { |
149 | $self->respond ("302 dirslash", "", "location: $uri/\015\012"); |
150 | $self->respond ("302 dirslash", "", "location: $uri/\015\012"); |
150 | |
151 | |
151 | } elsif ($uri eq "/debug") { # for debugging |
152 | } elsif ($uri eq "/debug") { # for debugging |
152 | my @body = "<html><body>"; |
153 | my @body = "<html><body>"; |
153 | |
154 | |
154 | for my $type (6, 5, 4, 3, 2, 1, 0) { |
155 | for my $type (6, 5, 4, 3, 2, 1, 0) { |
155 | push @body, "<h1>$type</h1>"; |
156 | push @body, "<h1>$type</h1><table><tr><th>#</th><th>csum</th><th>size</th><th>name</th><th>meta</th></tr>"; |
156 | |
157 | |
157 | for (1 .. cf::face::faces_size - 1) { |
158 | for (1 .. cf::face::faces_size - 1) { |
158 | cf::cede_to_tick; |
159 | cf::cede_to_tick; |
159 | |
160 | |
160 | next if $type != cf::face::get_type $_; |
161 | next if $type != cf::face::get_type $_; |
161 | my $name = cf::face::get_name $_; |
162 | my $name = cf::face::get_name $_; |
162 | my $id = unpack "H*", cf::face::get_chksum $_, 1; |
163 | my $id = unpack "H*", cf::face::get_csum $_, 0; |
163 | push @body, "$_ <a href='$id'>$name ($id)</a>"; |
164 | push @body, "<tr><td>$_</td><td>$id</td><td>$cf::face::SIZE[0][$_]</td><td><a href='$id'>$name</a></td>"; |
164 | push @body, " <a href='${id}M'>(meta)</a>" if $type & 1; |
165 | push @body, "<td><a href='${id}M'>meta</a>" if $type & 1; |
165 | push @body, "<br>"; |
166 | push @body, "</tr>"; |
166 | } |
167 | } |
|
|
168 | |
|
|
169 | push @body, "</table>"; |
167 | } |
170 | } |
168 | |
171 | |
169 | push @body, "</body></html>"; |
172 | push @body, "</body></html>"; |
170 | |
173 | |
171 | my $body = join "", @body; |
174 | my $body = join "", @body; |