# gitweb: in-page errors don't work with mod_perl

8 messages from 2011-11-27 to 2011-11-29. Participants: Jürgen Kreileder, Jakub Narebski.
Thread: https://gitlist.dev/t/29025

## Jürgen Kreileder, 2011-11-27 04:05

Subject: gitweb: in-page errors don't work with mod_perl
Message-ID: <CAKD0UuweWoY5ObXgyN9vrOXWrKdNYWuG7CGB0V7HvcuiwRJD+A@mail.gmail.com>
URL: https://gitlist.dev/e/CAKD0UuweWoY5ObXgyN9vrOXWrKdNYWuG7CGB0V7HvcuiwRJD%2BA%40mail.gmail.com

```
Hi

when gitweb.perl (208a1cc3d3) is run with mod_perl2 (2.0.5-2ubuntu1 on
Ubuntu 11.10) custom error pages don't work: Any page with status !=
200 shows the plain Apache error document instead of a gitweb's error
page.


Jürgen

-- 
http://blog.blackdown.de/
http://www.flickr.com/photos/jkreileder/

```

## Jakub Narebski, 2011-11-27 22:43

Subject: Re: gitweb: in-page errors don't work with mod_perl
Message-ID: <m339d9mbiu.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m339d9mbiu.fsf%40localhost.localdomain
In-Reply-To: <CAKD0UuweWoY5ObXgyN9vrOXWrKdNYWuG7CGB0V7HvcuiwRJD+A@mail.gmail.com>

```
Hello!

Jürgen Kreileder <jk@blackdown.de> writes:

> when gitweb.perl (208a1cc3d3) is run with mod_perl2 (2.0.5-2ubuntu1 on
> Ubuntu 11.10) custom error pages don't work: Any page with status !=
> 200 shows the plain Apache error document instead of a gitweb's error
> page.

Thanks for reporting it.  I wonder if it worked at all anytime...

Anyway, does the following patch fixes this issue for you?

-- >8 --
Subject: [PATCH] gitweb: Fix error handling for mod_perl

When gitweb was run with mod_perl2 (using ModPerl::Registry), the
custom error pages don't work: Any page with status != 200 had the
plain Apache error document appended to a gitweb's error page, e.g.

  <?xml version="1.0" encoding="utf-8"?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  ...
  </html><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  <html><head>
  <title>404 Not Found</title>
  </head><body>
  <h1>Not Found</h1>
  <p>The requested URL ... was not found on this server.</p>
  <hr>
  <address>Apache/2.0.54 (Fedora) Server at localhost Port 80</address>
  </body></html>

When serving gitweb with application/xhtml+xml mimetype this results
in malformed XML and some browsers do not showing output at all.


The solution used by this commit is to tell mod_perl that it is O.K.,
and we handled all errors by ourselves.

This make us not depend in whether there is or not

  PerlOptions +ParseHeaders

in Apache configuration section for mod_perl.

Reported-by: Jürgen Kreileder <jk@blackdown.de>
Signed-off-by: Jakub Narębski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 4f0c3bd..f51cce1 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1239,6 +1239,11 @@ sub run {
 
 run();
 
+if ($ENV{'MOD_PERL'}) {
+	# mod_perl needs to be told that error page was already created
+	my $r = $cgi->r;
+	$r->status(200);
+}
 if (defined caller) {
 	# wrapped in a subroutine processing requests,
 	# e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
-- 
1.7.6

```

## Jürgen Kreileder, 2011-11-28 00:20

Subject: Re: gitweb: in-page errors don't work with mod_perl
Message-ID: <CAKD0UuwJoRkd7J06d2mFgyN0tO8p8ETPrwW5DqX12m+c_tQz4A@mail.gmail.com>
URL: https://gitlist.dev/e/CAKD0UuwJoRkd7J06d2mFgyN0tO8p8ETPrwW5DqX12m%2Bc_tQz4A%40mail.gmail.com
In-Reply-To: <m339d9mbiu.fsf@localhost.localdomain>

```
2011/11/27 Jakub Narebski <jnareb@gmail.com>:
> Jürgen Kreileder <jk@blackdown.de> writes:
>
>> when gitweb.perl (208a1cc3d3) is run with mod_perl2 (2.0.5-2ubuntu1 on
>> Ubuntu 11.10) custom error pages don't work: Any page with status !=
>> 200 shows the plain Apache error document instead of a gitweb's error
>> page.
>
> Thanks for reporting it.  I wonder if it worked at all anytime...
>
> Anyway, does the following patch fixes this issue for you?

Not really.  It does make the errors appear inline on the standard gitweb pages.
But the HTTP status code is broken now: It's always 200 OK.


> Reported-by: Jürgen Kreileder <jk@blackdown.de>
> Signed-off-by: Jakub Narębski <jnareb@gmail.com>
> ---
>  gitweb/gitweb.perl |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 4f0c3bd..f51cce1 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -1239,6 +1239,11 @@ sub run {
>
>  run();
>
> +if ($ENV{'MOD_PERL'}) {
> +       # mod_perl needs to be told that error page was already created
> +       my $r = $cgi->r;
> +       $r->status(200);
> +}
>  if (defined caller) {
>        # wrapped in a subroutine processing requests,
>        # e.g. mod_perl with ModPerl::Registry, or PSGI with Plack::App::WrapCGI
> --
> 1.7.6
>
>

Jürgen

```

## Jürgen Kreileder, 2011-11-28 20:13

Subject: Re: gitweb: in-page errors don't work with mod_perl
Message-ID: <CAKD0Uuws=zU+Pg8afn91mm0t4Rp_GNF++dTYnjA9okndyR=cXQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAKD0Uuws%3DzU%2BPg8afn91mm0t4Rp_GNF%2B%2BdTYnjA9okndyR%3DcXQ%40mail.gmail.com
In-Reply-To: <201111281754.59205.jnareb@gmail.com>

```
On Mon, Nov 28, 2011 at 17:54, Jakub Narebski <jnareb@gmail.com> wrote:
 [...]
>
> The configuration is very similar.  Perhaps that is the difference between
> Apache 2.0.x (mine) and Apache 2.2.x (yours).
>
> Does adding `$r->err_headers_out();` before `$r->status(200);` helps?
> I'm grasping at straws here.  mod_perl documentation is not very helpful.

Doesn't help unfortunately.  It's hard to find any information about
this on the net (except for your comment on stackoverflow :).

The only way to get mod_perl to return a custom error message with
correct status code I've found so far is $r->custom_response($status,
$msg).  Unfortunately mod_perl then ignores header I set, e.g.
content-type.


Juergen

```

## Jürgen Kreileder, 2011-11-28 21:42

Subject: Re: gitweb: in-page errors don't work with mod_perl
Message-ID: <CAKD0UuzsV7A_j8YD4b0Lb95L2NcRcSu5PH8C9aZQmEx3tOuQjQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAKD0UuzsV7A_j8YD4b0Lb95L2NcRcSu5PH8C9aZQmEx3tOuQjQ%40mail.gmail.com
In-Reply-To: <CAKD0Uuws=zU+Pg8afn91mm0t4Rp_GNF++dTYnjA9okndyR=cXQ@mail.gmail.com>

```
On Mon, Nov 28, 2011 at 21:13, Jürgen Kreileder <jk@blackdown.de> wrote:
> On Mon, Nov 28, 2011 at 17:54, Jakub Narebski <jnareb@gmail.com> wrote:
>  [...]
>>
>> The configuration is very similar.  Perhaps that is the difference between
>> Apache 2.0.x (mine) and Apache 2.2.x (yours).
>>
>> Does adding `$r->err_headers_out();` before `$r->status(200);` helps?
>> I'm grasping at straws here.  mod_perl documentation is not very helpful.
>
> Doesn't help unfortunately.  It's hard to find any information about
> this on the net (except for your comment on stackoverflow :).
>
> The only way to get mod_perl to return a custom error message with
> correct status code I've found so far is $r->custom_response($status,
> $msg).  Unfortunately mod_perl then ignores headers I set, e.g.
> content-type.

I guess this explains it:
http://foertsch.name/ModPerl-Tricks/custom-content_type-with-custom_response.shtml
Requires quite some restructuring to gitweb.perl.


Juergen

```

## Jakub Narebski, 2011-11-28 22:32

Subject: Re: gitweb: in-page errors don't work with mod_perl
Message-ID: <201111282332.07276.jnareb@gmail.com>
URL: https://gitlist.dev/e/201111282332.07276.jnareb%40gmail.com
In-Reply-To: <CAKD0UuzsV7A_j8YD4b0Lb95L2NcRcSu5PH8C9aZQmEx3tOuQjQ@mail.gmail.com>

```
Jürgen Kreileder wrote:
> On Mon, Nov 28, 2011 at 21:13, Jürgen Kreileder <jk@blackdown.de> wrote:
> > On Mon, Nov 28, 2011 at 17:54, Jakub Narebski <jnareb@gmail.com> wrote:
> >  [...]
> > >
> > > The configuration is very similar.  Perhaps that is the difference between
> > > Apache 2.0.x (mine) and Apache 2.2.x (yours).
> > >
> > > Does adding `$r->err_headers_out();` before `$r->status(200);` helps?
> > > I'm grasping at straws here.  mod_perl documentation is not very helpful.
> >
> > Doesn't help unfortunately.  It's hard to find any information about
> > this on the net (except for your comment on stackoverflow :).
> >
> > The only way to get mod_perl to return a custom error message with
> > correct status code I've found so far is $r->custom_response($status,
> > $msg).  Unfortunately mod_perl then ignores headers I set, e.g.
> > content-type.
> 
> I guess this explains it:
> http://foertsch.name/ModPerl-Tricks/custom-content_type-with-custom_response.shtml
> Requires quite some restructuring to gitweb.perl.

I'm coming close to declaring that ModPerl::Registry is horribly broken
with respect to error pages created by CGI, and say that we don't support
it, removing mod_perl configuration examples from gitweb documentation.

WTF 'return Apache2::Const::DONE;' doesn't work with ModPerl::Registry?
It is supposed to work with native mod_perl scripts...

-- 
Jakub Narebski
Poland

```

## Jürgen Kreileder, 2011-11-28 23:40

Subject: Re: gitweb: in-page errors don't work with mod_perl
Message-ID: <CAKD0Uuw35Kdno=OxqP5SYtaVjqUFZCLL9fSSscN7sq=KmycyxA@mail.gmail.com>
URL: https://gitlist.dev/e/CAKD0Uuw35Kdno%3DOxqP5SYtaVjqUFZCLL9fSSscN7sq%3DKmycyxA%40mail.gmail.com
In-Reply-To: <201111282332.07276.jnareb@gmail.com>

```
On Mon, Nov 28, 2011 at 23:32, Jakub Narebski <jnareb@gmail.com> wrote:
> Jürgen Kreileder wrote:
>> On Mon, Nov 28, 2011 at 21:13, Jürgen Kreileder <jk@blackdown.de> wrote:
>> > On Mon, Nov 28, 2011 at 17:54, Jakub Narebski <jnareb@gmail.com> wrote:
>> >  [...]
>> > >
>> > > The configuration is very similar.  Perhaps that is the difference between
>> > > Apache 2.0.x (mine) and Apache 2.2.x (yours).
>> > >
>> > > Does adding `$r->err_headers_out();` before `$r->status(200);` helps?
>> > > I'm grasping at straws here.  mod_perl documentation is not very helpful.
>> >
>> > Doesn't help unfortunately.  It's hard to find any information about
>> > this on the net (except for your comment on stackoverflow :).
>> >
>> > The only way to get mod_perl to return a custom error message with
>> > correct status code I've found so far is $r->custom_response($status,
>> > $msg).  Unfortunately mod_perl then ignores headers I set, e.g.
>> > content-type.
>>
>> I guess this explains it:
>> http://foertsch.name/ModPerl-Tricks/custom-content_type-with-custom_response.shtml
>> Requires quite some restructuring to gitweb.perl.
>
> I'm coming close to declaring that ModPerl::Registry is horribly broken
> with respect to error pages created by CGI, and say that we don't support
> it, removing mod_perl configuration examples from gitweb documentation.

Makes sense.  The benefits of mod_perl are properly small for gitweb anyway.


Juergen

-- 
http://blog.blackdown.de/
http://www.flickr.com/photos/jkreileder/

```

## Jakub Narebski, 2011-11-29 00:49

Subject: Re: gitweb: in-page errors don't work with mod_perl
Message-ID: <201111290149.36931.jnareb@gmail.com>
URL: https://gitlist.dev/e/201111290149.36931.jnareb%40gmail.com
In-Reply-To: <CAKD0Uuw35Kdno=OxqP5SYtaVjqUFZCLL9fSSscN7sq=KmycyxA@mail.gmail.com>

```
Jürgen Kreileder wrote:
> On Mon, Nov 28, 2011 at 23:32, Jakub Narebski <jnareb@gmail.com> wrote:
>> Jürgen Kreileder wrote:
>>> On Mon, Nov 28, 2011 at 21:13, Jürgen Kreileder <jk@blackdown.de> wrote:
>>>> On Mon, Nov 28, 2011 at 17:54, Jakub Narebski <jnareb@gmail.com> wrote:
>>>>  [...]
>>>>>
>>>>> The configuration is very similar.  Perhaps that is the difference between
>>>>> Apache 2.0.x (mine) and Apache 2.2.x (yours).
>>>>>
>>>>> Does adding `$r->err_headers_out();` before `$r->status(200);` helps?
>>>>> I'm grasping at straws here.  mod_perl documentation is not very helpful.
>>>>
>>>> Doesn't help unfortunately.  It's hard to find any information about
>>>> this on the net (except for your comment on stackoverflow :).
>>>>
>>>> The only way to get mod_perl to return a custom error message with
>>>> correct status code I've found so far is $r->custom_response($status,
>>>> $msg).  Unfortunately mod_perl then ignores headers I set, e.g.
>>>> content-type.
>>>
>>> I guess this explains it:
>>> http://foertsch.name/ModPerl-Tricks/custom-content_type-with-custom_response.shtml
>>> Requires quite some restructuring to gitweb.perl.
>>
>> I'm coming close to declaring that ModPerl::Registry is horribly broken
>> with respect to error pages created by CGI, and say that we don't support
>> it, removing mod_perl configuration examples from gitweb documentation.
> 
> Makes sense.  The benefits of mod_perl are properly small for gitweb anyway.

Anyway you can run gitweb with FastCGI (supposedly - I don't know if it
was tested), which provides the same (or most of the) advantages that
mod_perl gives, without the troubles.  Just rename gitweb.cgi to
gitweb.fcgi and configure web server appropriately (and have FCGI Perl
module installed).

-- 
Jakub Narebski
Poland

```
