From: Sergio Talens-Oliag <sto@iti.es>
To: git@vger.kernel.org
Subject: Gitweb running as FCGI does not print its output in UTF-8
Date: Thu, 20 Dec 2012 14:53:57 +0100 [thread overview]
Message-ID: <20121220135357.GA27920@iti.es> (raw)
[-- Attachment #1: Type: text/plain, Size: 2931 bytes --]
Hello, I'm sending this message to explain a problem I've found with
gitweb.cgi when running it using a call like the following:
export FCGI_SOCKET_PATH="/run/gitweb.socket"
gitweb.cgi --fcgi --nproc 2
I've fixed the problem for my installation usign a wrapper script, as
explained below.
I'm not sending a patch because I'm no expert in Perl and I'm unsure that
the solution I've found is the right one, but in the hope that my description
of the problem and the provided solution will be useful for others.
Problem description:
When using gitweb.cgi in FCGI mode the answers from the script are returned
using the wrong encoding (UTF-8 characters are printed as LATIN-1).
It seems that the problem appears because the FCGI streams are implemented
using the older stream API, TIEHANDLE and applying PerlIO layers using
binmode() has no effect to them.
Applied solution:
A solution similar to the use of binmode for the output stream is to
redefine the FCGI::Stream::PRINT function to use UTF-8 as output encoding.
To do it with minimal chages I've created a gitweb.cgi wrapper that
redefines the function and runs the original script; I'm doing it like this
to be able to use the packaged script until upstream includes a fix for the
problem.
Wrapper code (uses /usr/share/gitweb/gitweb.cgi as the PATH for gitweb.cgi):
#!/usr/bin/perl
# gitweb.cgi wrapper that fixes the UTF-8 problem with fastcgi
# Local redefinition of FCGI::Stream::PRINT
use Encode;
use FCGI;
our $enc = Encode::find_encoding('UTF-8');
our $org = \&FCGI::Stream::PRINT;
no warnings 'redefine';
local *FCGI::Stream::PRINT = sub {
my @OUTPUT = @_;
for (my $i = 1; $i < @_; $i++) {
$OUTPUT[$i] = $enc->encode($_[$i], Encode::FB_CROAK|Encode::LEAVE_SRC);
}
@_ = @OUTPUT;
goto $org;
};
# Execute original script
do "/usr/share/gitweb/gitweb.cgi";
References:
The applied solution has been found on the following StackOverflow
question:
http://stackoverflow.com/questions/5005104
Environment:
The system I'm using is Debian Wheezy and I'm serving gitweb using nginx's
fastcgi interface.
The versions of the related debian packages are:
Package: git
Version: 1:1.7.10.4-1+wheezy1
Package: libcgi-fast-perl
Version: 5.14.2-16
Package: libfcgi-procmanager-perl
Version: 0.24-1
Package: perl
Version: 5.14.2-16
To launch gitweb as fastcgi I'm using an init.d script that runs the wrapper
script in the background as the `www-user` using a call similar to the
following:
export FCGI_SOCKET_PATH="/run/gitweb/socket"
gitweb.cgi-wrapper --fcgi --nproc 2
Greetings,
Sergio.
--
Sergio Talens-Oliag <sto@iti.es> <http://www.iti.es/>
Key fingerprint = FF77 A16B 9D09 FC7B 6656 CFAD 261D E19A 578A 36F2
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
reply other threads:[~2012-12-20 14:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121220135357.GA27920@iti.es \
--to=sto@iti.es \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).