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 301 => 'Moved Permanently',
22 405 => 'Method Not Allowed',
23 501 => 'Not Implemented',
27 # some servers (Ruby webrick) include scheme://host[:port] here,
28 # which confuses CGI.pm when generating self_url.
29 # RFC 3875 does not mention REQUEST_URI at all,
30 # so nuke it since CGI.pm functions without it.
31 delete $ENV{REQUEST_URI};
32 $ENV{SCRIPT_NAME} = '' if $NO_SCRIPT_NAME;
34 my $ret = PublicInbox::WWW::run($req, $req->request_method);
39 if (ref($ret) eq 'CODE') {
42 my ($status, $headers, $body) = @$ret;
44 dump_header([$status, $headers])->write($body->[0]);
50 my ($status, $headers) = @$res;
51 $fh->write("Status: $status $HTTP_CODES{$status}\r\n");
53 while (my ($k, $v) = splice(@tmp, 0, 2)) {
54 $fh->write("$k: $v\r\n");