2 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
5 # Enables using PublicInbox::WWW as a CGI script
10 use CGI qw/-nosticky/;
14 $NO_SCRIPT_NAME = 1 if $ENV{NO_SCRIPT_NAME};
17 PublicInbox::WWW->preload;
22 300 => 'Multiple Choices',
23 301 => 'Moved Permanently',
26 405 => 'Method Not Allowed',
27 501 => 'Not Implemented',
31 # some servers (Ruby webrick) include scheme://host[:port] here,
32 # which confuses CGI.pm when generating self_url.
33 # RFC 3875 does not mention REQUEST_URI at all,
34 # so nuke it since CGI.pm functions without it.
35 delete $ENV{REQUEST_URI};
36 $ENV{SCRIPT_NAME} = '' if $NO_SCRIPT_NAME;
38 my $ret = PublicInbox::WWW::run($req, $req->request_method);
43 if (ref($ret) eq 'CODE') {
46 my ($status, $headers, $body) = @$ret;
48 dump_header([$status, $headers])->write($body->[0]);
54 my ($status, $headers) = @$res;
55 $fh->write("Status: $status $HTTP_CODES{$status}\r\n");
57 while (my ($k, $v) = splice(@tmp, 0, 2)) {
58 $fh->write("$k: $v\r\n");