]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/WWW.pm
www: admin-configurable CSS via "publicinbox.css"
[public-inbox.git] / lib / PublicInbox / WWW.pm
1 # Copyright (C) 2014-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 #
4 # Main web interface for mailing list archives
5 #
6 # We focus on the lowest common denominators here:
7 # - targeted at text-only console browsers (w3m, links, etc..)
8 # - Only basic HTML, CSS only for line-wrapping <pre> text content for GUIs
9 #   and diff/syntax-highlighting (optional)
10 # - No JavaScript, graphics or icons allowed.
11 # - Must not rely on static content
12 # - UTF-8 is only for user-content, 7-bit US-ASCII for us
13 package PublicInbox::WWW;
14 use 5.008;
15 use strict;
16 use warnings;
17 use PublicInbox::Config;
18 use PublicInbox::Hval;
19 use URI::Escape qw(uri_unescape);
20 use PublicInbox::MID qw(mid_escape);
21 require PublicInbox::Git;
22 use PublicInbox::GitHTTPBackend;
23
24 # TODO: consider a routing tree now that we have more endpoints:
25 our $INBOX_RE = qr!\A/([\w\-][\w\.\-]*)!;
26 our $MID_RE = qr!([^/]+)!;
27 our $END_RE = qr!(T/|t/|t\.mbox(?:\.gz)?|t\.atom|raw|)!;
28 our $ATTACH_RE = qr!(\d[\.\d]*)-([[:alnum:]][\w\.-]+[[:alnum:]])!i;
29 our $OID_RE = qr![a-f0-9]{7,40}!;
30
31 sub new {
32         my ($class, $pi_config) = @_;
33         $pi_config ||= PublicInbox::Config->new;
34         bless { pi_config => $pi_config }, $class;
35 }
36
37 # backwards compatibility, do not use
38 sub run {
39         my ($req, $method) = @_;
40         PublicInbox::WWW->new->call($req->env);
41 }
42
43 my %path_re_cache;
44
45 sub path_re ($) {
46         my $sn = $_[0]->{SCRIPT_NAME};
47         $path_re_cache{$sn} ||= do {
48                 $sn = '/'.$sn unless index($sn, '/') == 0;
49                 $sn =~ s!/\z!!;
50                 qr!\A(?:https?://[^/]+)?\Q$sn\E(/[^\?\#]+)!;
51         };
52 }
53
54 sub call {
55         my ($self, $env) = @_;
56         my $ctx = { env => $env, www => $self };
57
58         # we don't care about multi-value
59         my %qp = map {
60                 utf8::decode($_);
61                 my ($k, $v) = split('=', uri_unescape($_), 2);
62                 $v = '' unless defined $v;
63                 $v =~ tr/+/ /;
64                 ($k, $v)
65         } split(/[&;]+/, $env->{QUERY_STRING});
66         $ctx->{qp} = \%qp;
67
68         # not using $env->{PATH_INFO} here since that's already decoded
69         my ($path_info) = ($env->{REQUEST_URI} =~ path_re($env));
70         my $method = $env->{REQUEST_METHOD};
71
72         if ($method eq 'POST') {
73                 if ($path_info =~ m!$INBOX_RE/(?:(\d+)/)?(git-upload-pack)\z!) {
74                         my ($part, $path) = ($2, $3);
75                         return invalid_inbox($ctx, $1) ||
76                                 serve_git($ctx, $part, $path);
77                 } elsif ($path_info =~ m!$INBOX_RE/!o) {
78                         return invalid_inbox($ctx, $1) || mbox_results($ctx);
79                 }
80         }
81         elsif ($method !~ /\AGET|HEAD\z/) {
82                 return r(405, 'Method Not Allowed');
83         }
84
85         # top-level indices and feeds
86         if ($path_info eq '/') {
87                 r404();
88         } elsif ($path_info =~ m!$INBOX_RE\z!o) {
89                 invalid_inbox($ctx, $1) || r301($ctx, $1);
90         } elsif ($path_info =~ m!$INBOX_RE(?:/|/index\.html)?\z!o) {
91                 invalid_inbox($ctx, $1) || get_index($ctx);
92         } elsif ($path_info =~ m!$INBOX_RE/(?:atom\.xml|new\.atom)\z!o) {
93                 invalid_inbox($ctx, $1) || get_atom($ctx);
94         } elsif ($path_info =~ m!$INBOX_RE/new\.html\z!o) {
95                 invalid_inbox($ctx, $1) || get_new($ctx);
96         } elsif ($path_info =~ m!$INBOX_RE/(?:(\d+)/)?
97                                 ($PublicInbox::GitHTTPBackend::ANY)\z!ox) {
98                 my ($part, $path) = ($2, $3);
99                 invalid_inbox($ctx, $1) || serve_git($ctx, $part, $path);
100         } elsif ($path_info =~ m!$INBOX_RE/([\w-]+).mbox\.gz\z!o) {
101                 serve_mbox_range($ctx, $1, $2);
102         } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$END_RE\z!o) {
103                 msg_page($ctx, $1, $2, $3);
104
105         } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/$ATTACH_RE\z!o) {
106                 my ($idx, $fn) = ($3, $4);
107                 invalid_inbox_mid($ctx, $1, $2) || get_attach($ctx, $idx, $fn);
108         # in case people leave off the trailing slash:
109         } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/(T|t)\z!o) {
110                 my ($inbox, $mid_ue, $suffix) = ($1, $2, $3);
111                 $suffix .= $suffix =~ /\A[tT]\z/ ? '/#u' : '/';
112                 r301($ctx, $inbox, $mid_ue, $suffix);
113
114         } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/R/?\z!o) {
115                 my ($inbox, $mid_ue) = ($1, $2);
116                 r301($ctx, $inbox, $mid_ue, '#R');
117
118         } elsif ($path_info =~ m!$INBOX_RE/$MID_RE/f/?\z!o) {
119                 r301($ctx, $1, $2);
120         } elsif ($path_info =~ m!$INBOX_RE/_/text(?:/(.*))?\z!o) {
121                 get_text($ctx, $1, $2);
122         } elsif ($path_info =~ m!$INBOX_RE/([\w\-\.]+)\.css\z!o) {
123                 get_css($self, $2);
124         } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s/\z!o) {
125                 get_vcs_object($ctx, $1, $2);
126         } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s/([\w\.\-]+)\z!o) {
127                 get_vcs_object($ctx, $1, $2, $3);
128         } elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s\z!o) {
129                 r301($ctx, $1, $2, 's/');
130         # convenience redirects order matters
131         } elsif ($path_info =~ m!$INBOX_RE/([^/]{2,})\z!o) {
132                 r301($ctx, $1, $2);
133
134         } else {
135                 legacy_redirects($ctx, $path_info);
136         }
137 }
138
139 # for CoW-friendliness, MOOOOO!
140 sub preload {
141         my ($self) = @_;
142         require PublicInbox::Feed;
143         require PublicInbox::View;
144         require PublicInbox::SearchThread;
145         require PublicInbox::MIME;
146         require Digest::SHA;
147         require POSIX;
148
149         foreach (qw(PublicInbox::Search PublicInbox::SearchView
150                         PublicInbox::Mbox IO::Compress::Gzip
151                         PublicInbox::NewsWWW)) {
152                 eval "require $_;";
153         }
154         if (ref($self)) {
155                 $self->stylesheets_prepare($_) for ('', '../', '../../');
156         }
157 }
158
159 # private functions below
160
161 sub r404 {
162         my ($ctx) = @_;
163         if ($ctx && $ctx->{mid}) {
164                 require PublicInbox::ExtMsg;
165                 searcher($ctx);
166                 return PublicInbox::ExtMsg::ext_msg($ctx);
167         }
168         r(404, 'Not Found');
169 }
170
171 # simple response for errors
172 sub r { [ $_[0], ['Content-Type' => 'text/plain'], [ join(' ', @_, "\n") ] ] }
173
174 # returns undef if valid, array ref response if invalid
175 sub invalid_inbox ($$) {
176         my ($ctx, $inbox) = @_;
177         my $www = $ctx->{www};
178         my $obj = $www->{pi_config}->lookup_name($inbox);
179         if (defined $obj) {
180                 $ctx->{git} = $obj->git;
181                 $ctx->{-inbox} = $obj;
182                 return;
183         }
184
185         # sometimes linkifiers (not ours!) screw up automatic link
186         # generation and link things intended for nntp:// to https?://,
187         # so try to infer links and redirect them to the appropriate
188         # list URL.
189         $www->news_www->call($ctx->{env});
190 }
191
192 # returns undef if valid, array ref response if invalid
193 sub invalid_inbox_mid {
194         my ($ctx, $inbox, $mid_ue) = @_;
195         my $ret = invalid_inbox($ctx, $inbox);
196         return $ret if $ret;
197
198         my $mid = $ctx->{mid} = uri_unescape($mid_ue);
199         my $ibx = $ctx->{-inbox};
200         if ($mid =~ m!\A([a-f0-9]{2})([a-f0-9]{38})\z!) {
201                 my ($x2, $x38) = ($1, $2);
202                 # this is horrifically wasteful for legacy URLs:
203                 my $str = $ctx->{-inbox}->msg_by_path("$x2/$x38") or return;
204                 require Email::Simple;
205                 my $s = Email::Simple->new($str);
206                 $mid = PublicInbox::MID::mid_clean($s->header('Message-ID'));
207                 return r301($ctx, $inbox, mid_escape($mid));
208         }
209         undef;
210 }
211
212 # /$INBOX/new.atom                     -> Atom feed, includes replies
213 sub get_atom {
214         my ($ctx) = @_;
215         require PublicInbox::Feed;
216         PublicInbox::Feed::generate($ctx);
217 }
218
219 # /$INBOX/new.html                      -> HTML only
220 sub get_new {
221         my ($ctx) = @_;
222         require PublicInbox::Feed;
223         PublicInbox::Feed::new_html($ctx);
224 }
225
226 # /$INBOX/?r=$GIT_COMMIT                 -> HTML only
227 sub get_index {
228         my ($ctx) = @_;
229         require PublicInbox::Feed;
230         searcher($ctx);
231         if ($ctx->{env}->{QUERY_STRING} =~ /(?:\A|[&;])q=/) {
232                 require PublicInbox::SearchView;
233                 PublicInbox::SearchView::sres_top_html($ctx);
234         } else {
235                 PublicInbox::Feed::generate_html_index($ctx);
236         }
237 }
238
239 # /$INBOX/$MESSAGE_ID/raw                    -> raw mbox
240 sub get_mid_txt {
241         my ($ctx) = @_;
242         require PublicInbox::Mbox;
243         PublicInbox::Mbox::emit_raw($ctx) || r404($ctx);
244 }
245
246 # /$INBOX/$MESSAGE_ID/                   -> HTML content (short quotes)
247 sub get_mid_html {
248         my ($ctx) = @_;
249         require PublicInbox::View;
250         searcher($ctx);
251         PublicInbox::View::msg_page($ctx) || r404($ctx);
252 }
253
254 # /$INBOX/$MESSAGE_ID/t/
255 sub get_thread {
256         my ($ctx, $flat) = @_;
257         searcher($ctx) or return need_search($ctx);
258         $ctx->{flat} = $flat;
259         require PublicInbox::View;
260         PublicInbox::View::thread_html($ctx);
261 }
262
263 # /$INBOX/_/text/$KEY/
264 # /$INBOX/_/text/$KEY/raw
265 # KEY may contain slashes
266 sub get_text {
267         my ($ctx, $inbox, $key) = @_;
268         my $r404 = invalid_inbox($ctx, $inbox);
269         return $r404 if $r404;
270
271         require PublicInbox::WwwText;
272         PublicInbox::WwwText::get_text($ctx, $key);
273 }
274
275 # show git objects (blobs and commits)
276 # /$INBOX/_/$OBJECT_ID/show
277 # /$INBOX/_/${OBJECT_ID}_${FILENAME}
278 # KEY may contain slashes
279 sub get_vcs_object ($$$;$) {
280         my ($ctx, $inbox, $oid, $filename) = @_;
281         my $r404 = invalid_inbox($ctx, $inbox);
282         return $r404 if $r404;
283         require PublicInbox::ViewVCS;
284         PublicInbox::ViewVCS::show($ctx, $oid, $filename);
285 }
286
287 sub ctx_get {
288         my ($ctx, $key) = @_;
289         my $val = $ctx->{$key};
290         (defined $val && $val ne '') or die "BUG: bad ctx, $key unusable";
291         $val;
292 }
293
294 # search support is optional, returns undef if Xapian is not installed
295 # or not configured for the given GIT_DIR
296 sub searcher {
297         my ($ctx) = @_;
298         eval {
299                 require PublicInbox::Search;
300                 $ctx->{srch} = $ctx->{-inbox}->search;
301         };
302 }
303
304 sub need_search {
305         my ($ctx) = @_;
306         my $msg = <<EOF;
307 <html><head><title>Search not available for this
308 public-inbox</title><body><pre>Search is not available for this public-inbox
309 <a href="../">Return to index</a></pre></body></html>
310 EOF
311         [ 501, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ $msg ] ];
312 }
313
314 # /$INBOX/$MESSAGE_ID/t.mbox           -> thread as mbox
315 # /$INBOX/$MESSAGE_ID/t.mbox.gz        -> thread as gzipped mbox
316 # note: I'm not a big fan of other compression formats since they're
317 # significantly more expensive on CPU than gzip and less-widely available,
318 # especially on older systems.  Stick to zlib since that's what git uses.
319 sub get_thread_mbox {
320         my ($ctx, $sfx) = @_;
321         my $srch = searcher($ctx) or return need_search($ctx);
322         require PublicInbox::Mbox;
323         PublicInbox::Mbox::thread_mbox($ctx, $srch, $sfx);
324 }
325
326
327 # /$INBOX/$MESSAGE_ID/t.atom              -> thread as Atom feed
328 sub get_thread_atom {
329         my ($ctx) = @_;
330         searcher($ctx) or return need_search($ctx);
331         require PublicInbox::Feed;
332         PublicInbox::Feed::generate_thread_atom($ctx);
333 }
334
335 sub legacy_redirects {
336         my ($ctx, $path_info) = @_;
337
338         # single-message pages
339         if ($path_info =~ m!$INBOX_RE/m/(\S+)/\z!o) {
340                 r301($ctx, $1, $2);
341         } elsif ($path_info =~ m!$INBOX_RE/m/(\S+)/raw\z!o) {
342                 r301($ctx, $1, $2, 'raw');
343
344         } elsif ($path_info =~ m!$INBOX_RE/f/(\S+)/\z!o) {
345                 r301($ctx, $1, $2);
346
347         # thread display
348         } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)/\z!o) {
349                 r301($ctx, $1, $2, 't/#u');
350
351         } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)/mbox(\.gz)?\z!o) {
352                 r301($ctx, $1, $2, "t.mbox$3");
353
354         # even older legacy redirects
355         } elsif ($path_info =~ m!$INBOX_RE/m/(\S+)\.html\z!o) {
356                 r301($ctx, $1, $2);
357
358         } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)\.html\z!o) {
359                 r301($ctx, $1, $2, 't/#u');
360
361         } elsif ($path_info =~ m!$INBOX_RE/f/(\S+)\.html\z!o) {
362                 r301($ctx, $1, $2);
363
364         } elsif ($path_info =~ m!$INBOX_RE/(?:m|f)/(\S+)\.txt\z!o) {
365                 r301($ctx, $1, $2, 'raw');
366
367         } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)(\.mbox(?:\.gz)?)\z!o) {
368                 r301($ctx, $1, $2, "t$3");
369
370         # legacy convenience redirects, order still matters
371         } elsif ($path_info =~ m!$INBOX_RE/m/(\S+)\z!o) {
372                 r301($ctx, $1, $2);
373         } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)\z!o) {
374                 r301($ctx, $1, $2, 't/#u');
375         } elsif ($path_info =~ m!$INBOX_RE/f/(\S+)\z!o) {
376                 r301($ctx, $1, $2);
377
378         # some Message-IDs have slashes in them and the HTTP server
379         # may try to be clever and unescape them :<
380         } elsif ($path_info =~ m!$INBOX_RE/(\S+/\S+)/$END_RE\z!o) {
381                 msg_page($ctx, $1, $2, $3);
382
383         # in case people leave off the trailing slash:
384         } elsif ($path_info =~ m!$INBOX_RE/(\S+/\S+)/(T|t)\z!o) {
385                 r301($ctx, $1, $2, $3 eq 't' ? 't/#u' : $3);
386         } elsif ($path_info =~ m!$INBOX_RE/(\S+/\S+)/f\z!o) {
387                 r301($ctx, $1, $2);
388         } else {
389                 $ctx->{www}->news_www->call($ctx->{env});
390         }
391 }
392
393 sub r301 {
394         my ($ctx, $inbox, $mid_ue, $suffix) = @_;
395         my $obj = $ctx->{-inbox};
396         unless ($obj) {
397                 my $r404 = invalid_inbox($ctx, $inbox);
398                 return $r404 if $r404;
399                 $obj = $ctx->{-inbox};
400         }
401         my $url = $obj->base_url($ctx->{env});
402         my $qs = $ctx->{env}->{QUERY_STRING};
403         if (defined $mid_ue) {
404                 # common, and much nicer as '@' than '%40':
405                 $mid_ue =~ s/%40/@/g;
406                 $url .= $mid_ue . '/';
407         }
408         $url .= $suffix if (defined $suffix);
409         $url .= "?$qs" if $qs ne '';
410
411         [ 301,
412           [ Location => $url, 'Content-Type' => 'text/plain' ],
413           [ "Redirecting to $url\n" ] ]
414 }
415
416 sub msg_page {
417         my ($ctx, $inbox, $mid_ue, $e) = @_;
418         my $ret;
419         $ret = invalid_inbox_mid($ctx, $inbox, $mid_ue) and return $ret;
420         '' eq $e and return get_mid_html($ctx);
421         'T/' eq $e and return get_thread($ctx, 1);
422         't/' eq $e and return get_thread($ctx);
423         't.atom' eq $e and return get_thread_atom($ctx);
424         't.mbox' eq $e and return get_thread_mbox($ctx);
425         't.mbox.gz' eq $e and return get_thread_mbox($ctx, '.gz');
426         'raw' eq $e and return get_mid_txt($ctx);
427
428         # legacy, but no redirect for compatibility:
429         'f/' eq $e and return get_mid_html($ctx);
430         r404($ctx);
431 }
432
433 sub serve_git {
434         my ($ctx, $part, $path) = @_;
435         my $env = $ctx->{env};
436         my $ibx = $ctx->{-inbox};
437         my $git = defined $part ? $ibx->git_part($part) : $ibx->git;
438         $git ? PublicInbox::GitHTTPBackend::serve($env, $git, $path) : r404();
439 }
440
441 sub mbox_results {
442         my ($ctx) = @_;
443         if ($ctx->{env}->{QUERY_STRING} =~ /(?:\A|[&;])q=/) {
444                 searcher($ctx) or return need_search($ctx);
445                 require PublicInbox::SearchView;
446                 return PublicInbox::SearchView::mbox_results($ctx);
447         }
448         r404();
449 }
450
451 sub serve_mbox_range {
452         my ($ctx, $inbox, $range) = @_;
453         invalid_inbox($ctx, $inbox) || eval {
454                 require PublicInbox::Mbox;
455                 searcher($ctx);
456                 PublicInbox::Mbox::emit_range($ctx, $range);
457         }
458 }
459
460 sub news_www {
461         my ($self) = @_;
462         $self->{news_www} ||= do {
463                 require PublicInbox::NewsWWW;
464                 PublicInbox::NewsWWW->new($self->{pi_config});
465         }
466 }
467
468 sub get_attach {
469         my ($ctx, $idx, $fn) = @_;
470         require PublicInbox::WwwAttach;
471         PublicInbox::WwwAttach::get_attach($ctx, $idx, $fn);
472 }
473
474 # User-generated content (UGC) may have excessively long lines
475 # and screw up rendering on some browsers, so we use pre-wrap.
476 #
477 # We also force everything to the same scaled font-size because GUI
478 # browsers (tested both Firefox and surf (webkit)) uses a larger font
479 # for the Search <form> element than the rest of the page.  Font size
480 # uniformity is important to people who rely on gigantic fonts.
481 # Finally, we use monospace to ensure the Search field and button
482 # has the same size and spacing as everything else which is
483 # <pre>-formatted anyways.
484 our $STYLE = 'pre{white-space:pre-wrap}*{font-size:100%;font-family:monospace}';
485
486 sub stylesheets_prepare ($$) {
487         my ($self, $upfx) = @_;
488         my $mini = eval {
489                 require CSS::Minifier;
490                 sub { CSS::Minifier::minify(input => $_[0]) };
491         } || eval {
492                 require CSS::Minifier::XS;
493                 sub { CSS::Minifier::XS::minify($_[0]) };
494         } || sub { $_[0] };
495
496         my $css_map = {};
497         my $stylesheets = $self->{pi_config}->{css} || [];
498         my $links = [];
499         my $inline_ok = 1;
500
501         foreach my $s (@$stylesheets) {
502                 my $attr = {};
503                 local $_ = $s;
504                 foreach my $k (qw(media title href)) {
505                         if (s/\s*$k='([^']+)'// || s/\s*$k=(\S+)//) {
506                                 $attr->{$k} = $1;
507                         }
508                 }
509
510                 if (defined $attr->{href}) {
511                         $inline_ok = 0;
512                 } else {
513                         open(my $fh, '<', $_) or do {
514                                 warn "failed to open $_: $!\n";
515                                 next;
516                         };
517                         my ($key) = (m!([^/]+?)(?:\.css)?\z!i);
518                         my $ctime = 0;
519                         my $local = do { local $/; <$fh> };
520                         if ($local =~ /\S/) {
521                                 $ctime = sprintf('%x',(stat($fh))[10]);
522                                 $local = $mini->($local);
523                         }
524                         $css_map->{$key} = $local;
525                         $attr->{href} = "$upfx$key.css?$ctime";
526                         if (defined($attr->{title})) {
527                                 $inline_ok = 0;
528                         } elsif (($attr->{media}||'screen') eq 'screen') {
529                                 $attr->{-inline} = $local;
530                         }
531                 }
532                 push @$links, $attr;
533         }
534
535         my $buf = "<style>$STYLE";
536         if ($inline_ok) {
537                 my @ext; # for media=print and whatnot
538                 foreach my $attr (@$links) {
539                         if (defined(my $str = delete $attr->{-inline})) {
540                                 $buf .= $str;
541                         } else {
542                                 push @ext, $attr;
543                         }
544                 }
545                 $links = \@ext;
546         }
547         $buf .= '</style>';
548
549         if (@$links) {
550                 foreach my $attr (@$links) {
551                         delete $attr->{-inline};
552                         $buf .= "<link\ntype=text/css\nrel=stylesheet";
553                         while (my ($k, $v) = each %$attr) {
554                                 $v = qq{"$v"} if $v =~ /[\s=]/;
555                                 $buf .= qq{\n$k=$v};
556                         }
557                         $buf .= ' />';
558                 }
559                 $self->{"-style-$upfx"} = $buf;
560         } else {
561                 $self->{-style_inline} = $buf;
562         }
563         $self->{-css_map} = $css_map;
564 }
565
566 # returns an HTML fragment with <style> or <link> tags in them
567 # Called by WwwStream by nearly every HTML page
568 sub style {
569         my ($self, $upfx) = @_;
570         $self->{-style_inline} || $self->{"-style-$upfx"} || do {
571                 stylesheets_prepare($self, $upfx);
572                 $self->{-style_inline} || $self->{"-style-$upfx"}
573         };
574 }
575
576 # /$INBOX/$KEY.css endpoint
577 # CSS is configured globally for all inboxes, but we access them on
578 # a per-inbox basis.  This allows administrators to setup per-inbox
579 # static routes to intercept the request before it hits PSGI
580 sub get_css ($$) {
581         my ($self, $key) = @_;
582         my $css_map = $self->{-css_map} || stylesheets_prepare($self, '');
583         defined(my $css = $css_map->{$key}) or return r404();
584         my $h = [ 'Content-Length', bytes::length($css),
585                 'Content-Type', 'text/css' ];
586         PublicInbox::GitHTTPBackend::cache_one_year($h);
587         [ 200, $h, [ $css ] ];
588 }
589
590 1;