git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: gitweb, FastCGI and PSGI/Plack

From
Tatsuhiko Miyagawa <miyagawa@gmail.com>
Date
May 10, 2010, 17:14 UTC
Message-ID
<AANLkTimcEjYpwa2xFhnRtnQ4ImfqJrDzQJdpptKNoskh@mail.gmail.com>
In-Reply-To
<201005101826.10735.jnareb@gmail.com>
On Mon, May 10, 2010 at 9:26 AM, Jakub Narebski <jnareb@gmail.com> wrote:
Show 5 quoted lines
> As I understand it, CGI::Compile catches all STDOUT output of compiled
> CGI script, and passes it to PSGI layer (PSGI interface).  That doesn't
> allow, I think, for serving request as it is generated.  This might be
> important for actions (pages) such as 'snapshot', 'blob_plain' and
> 'patches', which simply dump output of external comand to STDOUT.
Yes, good point.

PSGI allows "streaming response interface", which gives you a writer object to call ->write method, to implement the non-buffering output from your application. (Of course, returning IO::Handle is another way to do so, but that's "pull" style streaming, not "push" which is much easier when you convert CGI applications).

It would still require you to rewrite some of the gitweb.cgi HTML generation code, such as;

  # original
  my $cgi = CGI->new;
  print $cgi->header(...);
  print "<html>";
  print "<body>...";
into:
  # CGI::PSGI
  my $app = sub {
      my $env = shift;
      return sub {
          my $r = shift;
          my $cgi = CGI::PSGI->new($env);
          my $writer = $r->([ $cgi->header(...) ]);
          $writer->write("<html>");
          $writer->write("<body>...");
      }
  };

With some work to do the initialization and turn ->write call into a callback, it should be possible to make one code do both the normal CGI and PSGI.

> Also I think that currently you can currently see in web browser page as
> it is being generated by gitweb (e.g. 'projects_list' page).  This is
> impossible (I guess) with CGI::Compile.
Correct, and possible with CGI::PSGI.
> There is also a problem that there is no way, I guess, to automatically
> reload / refresh app if underlying CGI script changes (a la "plackup -r").

Yes there is. "plackup -R" can specify the path containing your cgi script to refresh whenever they're updated.

There's also "plackup -L Shotgun" to fork your application to get a fresh copy in every request, handy for the development.

-- 
Tatsuhiko Miyagawa
Previous: Jakub NarebskiNext: Tatsuhiko Miyagawa
Message 4 of 14 in “Re: gitweb, FastCGI and PSGI/Plack”
  1. Jakub NarebskiMay 9, 2010
  2. Tatsuhiko MiyagawaMay 10, 2010
  3. Jakub NarebskiMay 10, 2010
  4. Tatsuhiko MiyagawaMay 10, 2010
  5. Tatsuhiko MiyagawaMay 10, 2010
  6. Jakub NarebskiMay 10, 2010
  7. Tatsuhiko MiyagawaMay 10, 2010
  8. Jakub NarebskiMay 10, 2010
  9. Tatsuhiko MiyagawaMay 10, 2010
  10. Jakub NarebskiMay 10, 2010
  11. Tatsuhiko MiyagawaMay 11, 2010
  12. Jakub NarebskiMay 11, 2010
  13. Peter VereshaginMay 11, 2010
  14. Tatsuhiko MiyagawaMay 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.