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

Re: gitweb, FastCGI and PSGI/Plack

From
Jakub Narebski <jnareb@gmail.com>
Date
May 9, 2010, 23:05 UTC
Message-ID
<201005100105.49985.jnareb@gmail.com>
In-Reply-To
<g2s693254b91005091428ib188cbd1le5ffa90eace741a8@mail.gmail.com>
On Sun, 9 May 2010, Tatsuhiko Miyagawa wrote:
> I'm not subscribed to the git mailing list but:
> 
> http://www.spinics.net/lists/git/msg131014.html

You don't need to be subscribed to post to git mailing list. I personally read it with a news reader using GMane NNTP interface

  nntp://news.gmane.org/gmane.comp.version-control.git

but sending messages via email, to git@ver.kernel.org. Usually people reply both to original poster and to git mailing list, but just in case you can mention that you are not subscribed, and to not forget to send you a CC copy.

All CC re-added.
Show 6 quoted lines
> 
> > Actually both CGI and CGI::Fast are in Perl core distribution since
> > perl 5.004 (Perl 5.4.0).  I assume that CGI::Fast simply degrades to CGI
> > if FCGI module is not present.
> 
> No, it just dies if FCGI is not installed
Ah, so that is why CGI distribution has FCGI as requirement!
  http://deps.cpantesters.org/?module=CGI;perl=latest
> (so CGI::Fast in core doesn't make any sense).
Yes, it doesn't.
Nevertheless gitweb would try to require CGI::Fast only when it is run
with '--fastcgi' / '--fcgi' / '-f' option.  It should probably check if
it can be require'd without errors, like it is done for FCGI::ProcManager
in
  [RFC/PATCHv2 2/2] gitweb: Add support for FastCGI, using CGI::Fast
  Message-Id: <201005080959.01800.jnareb@gmail.com>
  http://article.gmane.org/gmane.comp.version-control.git/146647
Show 10 quoted lines
> 
> > JN> Yes, it can.  CGI::Compile is used for example by CGI::Emulate::PSGI,
> > JN> and you can run PSGI app on standalone Perl web server (pure Perl
> > JN> HTTP::Server::PSGI, or HTTP::Server::Simple::PSGI which in turn uses
> > JN> HTTP::Server::Simple, or Starman, or Twiggy, or Perlbal)
> 
> And FastCGI.
> 
> I don't understand why you implemented FastCGI interface *in addition
> to* PSGI/Plack interface.

I didn't implement support for PSGI/Plack, at least not in patch send in "[PATCH 0/2] gitweb: Add support for running gitweb as FastCGI script" series.

Adding support for FastCGI to CGI application is as simple as using CGI::Fast object in place of CGI, and wrapping running main subroutine in a loop that processes requests, like described in CGI::Fast manpage. Well, for gitweb it required a few more small changes, anyway...

Moving to PSGI, or adding possibility to run gitweb as PSGI script (like the series adds *ability* to run gitweb as FastCGI script) by modifying gitweb would not be that easy, even with help of CGI::PSGI.

CGI::Compile was referring to an alternate approach, where instead of modifying gitweb to be able to run it as FastCGI script (you can run it as CGI script and as ModPerl::Registry script from mod_perl) there was added gitweb.fcgi wrapper:

JN> The alternate solution would be to add gitweb.fcgi wrapper, like e.g.: JN> in the following patch by Eric Wong JN> JN> "[PATCH 1/2] gitweb: add a simple wrapper for FCGI support" JN> http://thread.gmane.org/gmane.comp.version-control.git/35920/focus=35921 JN> JN> which was part of the "[0/2 PATCH] FastCGI and nginx support for gitweb" JN> series. (Note that the patch does 'do $gitweb_cgi;' without checking for JN> errors, see the bottom of `perldoc -f do` documentation on how it should JN> be done).

One can of course use this approach wrapping gitweb to be run on PSGI, using CGI::Emulate::PSGI (via Plack::App::WrapCGI), which in turn uses CGI::Compile. The gitweb.fcgi wrapper could use CGI::Emulate::FCGI... if it existed.

NB I use the following gitweb.psgi wrapper to run gitweb from "plackup" for tests (after running "make gitweb", of course, and with appropriate gitweb_config.perl, unversioned, in gitweb/ alongside gitweb.perl, the gitweb.psgi wrapper, and generated gitweb.cgi):

-- 8< -- #!/usr/bin/env plackup

# gitweb - simple web interface to track changes in git repositories # PSGI wrapper (see http://plackperl.org)

use strict; use warnings;

use Plack::Builder; use Plack::App::WrapCGI; use CGI::Emulate::PSGI 0.07; # minimum version required to work

use File::Spec;
# __DIR__ is taken from Dir::Self __DIR__ fragment
sub __DIR__ () {
	File::Spec->rel2abs(join '', (File::Spec->splitpath(__FILE__))[0, 1]);
}
builder {
	enable 'Static',
		path => sub { m!\.(js|css|png)$! && s!^/gitweb/!! }, root => __DIR__."/";
	Plack::App::WrapCGI->new(script => __DIR__."/gitweb.cgi")->to_app;
}

__END__ -- >8 --

> 
> `plackup -s FCGI` makes your PSGI app a fastcgi handler using FCGI.pm,
> or `plackup -s Net::FastCGI` does the same but using Net::FastCGI,
> pure perl alternative.

It is a pity that Plack::App::WrapFCGI / FCGI::Emulate::PSGI does not exist, so that gitweb.psgi wrapper would not require indirectly CGI::Compile.

> 
> Come over to #plack (irc://irc.perl.org/#plack) for more discussion.
Email not good?
-- 
Jakub Narebski
ShadeHawk on #git, jnareb on #plack
Poland
Next: Tatsuhiko Miyagawa
Message 1 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.