2 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
12 $NO_SCRIPT_NAME = 1 if $ENV{NO_SCRIPT_NAME};
15 PublicInbox::WWW->preload;
20 300 => 'Multiple Choices',
21 301 => 'Moved Permanently',
24 405 => 'Method Not Allowed',
25 501 => 'Not Implemented',
29 # some servers (Ruby webrick) include scheme://host[:port] here,
30 # which confuses CGI.pm when generating self_url.
31 # RFC 3875 does not mention REQUEST_URI at all,
32 # so nuke it since CGI.pm functions without it.
33 delete $ENV{REQUEST_URI};
34 $ENV{SCRIPT_NAME} = '' if $NO_SCRIPT_NAME;
36 my $ret = PublicInbox::WWW::run($req, $req->request_method);
41 if (ref($ret) eq 'CODE') {
44 my ($status, $headers, $body) = @$ret;
46 dump_header([$status, $headers])->write($body->[0]);
52 my ($status, $headers) = @$res;
53 $fh->write("Status: $status $HTTP_CODES{$status}\r\n");
55 while (my ($k, $v) = splice(@tmp, 0, 2)) {
56 $fh->write("$k: $v\r\n");