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