-# only used for CGI and static file generation modes
-sub set_binmode {
- my ($headers) = @_;
- if ($headers->{'Content-Type'} eq 'text/plain') {
- # no way to validate raw messages, mixed encoding is possible.
- binmode STDOUT;
- } else { # strict encoding for HTML and XML
- binmode STDOUT, ':encoding(UTF-8)';
+sub psgi_app {
+ # preload so we are CoW friendly
+ require PublicInbox::Feed;
+ require PublicInbox::View;
+ require Mail::Thread;
+ require Digest::SHA;
+ require POSIX;
+ require XML::Atom::SimpleFeed;
+ require Plack::Request;
+ sub {
+ my $req = Plack::Request->new(@_);
+ main($req, $req->method);
+ };
+}
+
+sub cgi_print {
+ my ($ret) = @_;
+ my ($status, $headers, $body) = @$ret;
+ my %codes = (
+ 200 => 'OK',
+ 301 => 'Moved Permanently',
+ 404 => 'Not Found',
+ 405 => 'Method Not Allowed',
+ );
+
+ print "Status: $status $codes{$status}\r\n";
+ my @tmp = @$headers;
+ while (my ($k, $v) = splice(@tmp, 0, 2)) {
+ print "$k: $v\r\n";