From: Don Armstrong <don@donarmstrong.com>
Date: Thu, 6 Jul 2017 01:20:11 +0000 (-0700)
Subject: parse the status before outputting it
X-Git-Tag: release/2.6.0~95
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=452b0f878238b59e5c58b6357aea80d4055e25e0;p=debbugs.git

parse the status before outputting it
---

diff --git a/bin/local-debbugs b/bin/local-debbugs
index 4cfb7858..0223da14 100755
--- a/bin/local-debbugs
+++ b/bin/local-debbugs
@@ -224,7 +224,7 @@ EOF
 	  package local_debbugs::server;
 	  use IO::File;
 	  use HTTP::Server::Simple;
-	  use base qw(HTTP::Server::Simple::CGI);
+	  use base qw(HTTP::Server::Simple::CGI HTTP::Server::Simple::CGI::Environment);
 
 	  sub net_server {
 	       return 'Net::Server::Fork';
@@ -280,10 +280,28 @@ EOF
 	       }
 	       elsif ($path =~ m{^/?cgi(?:-bin)?/((?:(?:bug|pkg)report|version)\.cgi)}) {
 		    # dispatch to pkgreport.cgi
-		    print "HTTP/1.1 200 OK\n";
-		    exec("$options{cgi_bin}/$1") or
-			 die "Unable to execute $options{cgi_bin}/$1";
-	       }
+		    #print "HTTP/1.1 200 OK\n";
+		    open(my $fh,'-|',"$options{cgi_bin}/$1") or
+			die "Unable to execute $options{cgi_bin}/$1";
+		    my $status;
+		    my $cache = '';
+		    while (<$fh>) {
+			if (/Status: (\d+\s+.+?)\n?$/) {
+			    $status = $1;
+			    print "HTTP/1.1 $status\n";
+			    print STDERR "'$status'\n";
+			    last;
+			}
+			$cache .= $_;
+			if (/^$/) {
+			    print "HTTP/1.1 200 OK\n";
+			    last;
+			}
+		    }
+		    print $cache;
+		    print <$fh>;
+		    close($fh) or die "Unable to close";
+		}
 	       elsif ($path =~ m{^/?css/bugs.css}) {
 		    my $fh = IO::File->new($options{css},'r') or
 			 die "Unable to open $options{css} for reading: $!";