You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jean-Michel Hiver <jh...@mkdoc.com> on 2004/03/15 14:11:14 UTC

[BUG] Apache::Registry / 404 Not Found

Description:


The following CGI script:

    print <<EOF;
    Status: 404 Not Found
    Content-Type: text/plain

    Document not found
    EOF


Results in the following:

    Document not found
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <HTML><HEAD>
    <TITLE>404 Not Found</TITLE>
    </HEAD><BODY>
    <H1>Not Found</H1>
    The requested URL /perl-bin/bug.pl was not found on this server.<P>
    </BODY></HTML>

i.e. the Apache ErrorDocument is appended to the response.


There is a test to reproduce the bug:

    http://www.webmatrix.net/.static/bug-reporting-404-not-found-mp1.tar.gz


Tested with Apache/1.3.27 statically compiled with the latest stable 
mod_perl 1.29.


Very ugly temporary fix: Set the ErrorDocument directive to an 
almost-empty text file which containing just one space character.


Hope this helps.

Cheers,
Jean-Michel.


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Jean-Michel Hiver wrote:
> 
>> I don't think this is ever going to work in mp1 under Registry.  for the
>> most part, allowing a script to set the status of the response line is a
>> hack - I'm not sure how widely documented it is (I've only ever seen
>> it in
>> comments in Apache core myself) and I don't see the code at all in Apache
>> 2.0.
>>
> Well, it _does_ work properly under mod_cgi. Since Apache::Registry is
> supposed to emulate mod_cgi, I think it's a bug in Apache::Registry.

Registry is not a pure emulation of mod_cgi.  it tries to be and even does
an excellent job, but there are a few prices to be paid for the speed due to
the fact that it is, after all, an emulation enhanced for speed and not a
pure mod_cgi forked and buffered environment.  you've stumbed on to one of
them, but it's not surprising, seeing as how (as I mentioned) it's a rather
obscure feature you're using.

> Which is why I've sent a bug report using your most impressive test
> skeleton.

glad you like it :)  makes for a great starting point for projects, too...

> 
> Anyhow, I have the feeling that I'm going to have to stick with the
> empty ErrorDocument hack... As you mentioned off list it's really wrong,
> but at least it sort of works how it's supposed to be.

as Perrin suggested, PerlSendHeaders Off should be your ticket.  had I more
time at this moment I'd launch your skeleton to prove it.  but if
PerlSendHeaders Off doesn't work, I'll try and track it down some more -
you've given me a good starting point.  thanks :)

--Geoff


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Jean-Michel Hiver <jh...@mkdoc.com>.
>I don't think this is ever going to work in mp1 under Registry.  for the
>most part, allowing a script to set the status of the response line is a
>hack - I'm not sure how widely documented it is (I've only ever seen it in
>comments in Apache core myself) and I don't see the code at all in Apache
>2.0.
>
Well, it _does_ work properly under mod_cgi. Since Apache::Registry is 
supposed to emulate mod_cgi, I think it's a bug in Apache::Registry. 
Which is why I've sent a bug report using your most impressive test 
skeleton.


>nevertheless, it doesn't work in Apache::Registry because the first
>print calls $r->send_http_header, which sets the status line and response
>headers - it's too late in the process for apache to parse the data and set
>the response line.
>  
>
But there's only *one* print in this test script!

Anyhow, I have the feeling that I'm going to have to stick with the 
empty ErrorDocument hack... As you mentioned off list it's really wrong, 
but at least it sort of works how it's supposed to be.

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Jean-Michel Hiver wrote:
> Description:
> 
> 
> The following CGI script:
> 
>    print <<EOF;
>    Status: 404 Not Found
>    Content-Type: text/plain
> 
>    Document not found
>    EOF

I don't think this is ever going to work in mp1 under Registry.  for the
most part, allowing a script to set the status of the response line is a
hack - I'm not sure how widely documented it is (I've only ever seen it in
comments in Apache core myself) and I don't see the code at all in Apache
2.0.  nevertheless, it doesn't work in Apache::Registry because the first
print calls $r->send_http_header, which sets the status line and response
headers - it's too late in the process for apache to parse the data and set
the response line.

HTH

--Geoff



-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Jean-Michel Hiver <jh...@mkdoc.com>.
Perrin Harkins wrote:

>On Mon, 2004-03-15 at 16:23, Jean-Michel Hiver wrote:
>  
>
>>Yes, what I'm trying to achieve is get Apache::Registry to send custom 
>>404 pages - just like under mod_cgi.
>>    
>>
>
>I assume that means you want to be able to run the exact same script
>under mod_cgi?
>
Well, yes - otherwise i'd be using straight mod_perl handlers.

>And you don't want to make this script be your
>ErrorDocument?
>
I don't understand this part. Basically the script uses PATH_INFO to 
simulate a file structure.

For example, if you request '/foo/' it is really cgi-bin/script.cgi/foo/.

Now /foo/ might be an existing document, in which case I need to return 
a 200 OK.

But it might not exist, in which case I need to send a 404 and a custom 
error page.


If you're curious about why I'm trying to do this, it's on CPAN so you 
can take a look for yourself:

sudo perl -MCPAN -e 'install MKDoc::Core'


Installing a sample site is not too hard:

http://search.cpan.org/~jhiver/MKDoc-Core-0.1/lib/MKDoc/Core/Article/Installation.pm


At the moment I'm using the horrible 'empty ErrorDocument' hack... but 
it's a hack :(

>Basically, you need to turn off PerlSendHeader and
>manage the headers yourself.  One thing you could do is use the header()
>function in CGI.pm. This produces the same results under mod_cgi.
>  
>
So basically turning off PerlSendHeader and using CGI.pm. Interesting. 
I'll give it a shot.

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> Ok, I have changed the framework to use CGI.pm rather than printing the
> headers on STDOUT myself.
> 
> I _still_ get the same problem, wether or not PerlSendHeaders is turned
> on or off.
> It doesn't seem to make any difference whatsoever.
> 
> Is there any extra test I can write to pinpoint the problem?

ok, I took a look at your bug tarball (which, btw, made it much easier for
me to figure out exactly what you were trying to do and what the problem was
- thanks!)

basically, this will never be possible with Registry in mod_cgi emulation
mode.  you can subclass Apache::RegistryNG to make the required
manipulations transparent (and I can show you how), but short of that you
are out of luck.

however, in your test script you seem to be ok with using the mod_perl API -
you have a 'my $r = shift' in there.  in that case, you're in luck.
basically, to use the Status: hack in this way you need to be in total
control of the request.  luckily there is an official Apache API for this -
just return DONE from your handler to tell Apache to just move on to
logging, you have sent everything that needs to be sent.  in the case of
Registry, it's really $r->status(DONE) (which is just a hack to get around
Registry's subroutine wrapping and isn't the same as calling
$r->status(DONE) from a handler, which you should never do).

so, add that to your script and *poof* you're good to go.  I've uploaded
your tarball with the changes contained within.  I also updated your test
script a bit to help you be a little more idiomatic in your test writing (if
you're interested in that kind of thing).

  http://perl.apache.org/~geoff/bug-reporting-404-not-found-mp1.tar.gz

HTH

--Geoff


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Jean-Michel Hiver <jh...@mkdoc.com>.
Perrin Harkins wrote:

>On Mon, 2004-03-15 at 16:23, Jean-Michel Hiver wrote:
>  
>
>>Yes, what I'm trying to achieve is get Apache::Registry to send custom 
>>404 pages - just like under mod_cgi.
>>    
>>
>
>I assume that means you want to be able to run the exact same script
>under mod_cgi?  And you don't want to make this script be your
>ErrorDocument?  Basically, you need to turn off PerlSendHeader and
>manage the headers yourself.  One thing you could do is use the header()
>function in CGI.pm.  This produces the same results under mod_cgi.
>
Ok, I have changed the framework to use CGI.pm rather than printing the 
headers on STDOUT myself.

I _still_ get the same problem, wether or not PerlSendHeaders is turned 
on or off.
It doesn't seem to make any difference whatsoever.

Is there any extra test I can write to pinpoint the problem?

Any ideas?

Cheers,
Jean-Michel.


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2004-03-15 at 16:23, Jean-Michel Hiver wrote:
> Yes, what I'm trying to achieve is get Apache::Registry to send custom 
> 404 pages - just like under mod_cgi.

I assume that means you want to be able to run the exact same script
under mod_cgi?  And you don't want to make this script be your
ErrorDocument?  Basically, you need to turn off PerlSendHeader and
manage the headers yourself.  One thing you could do is use the header()
function in CGI.pm.  This produces the same results under mod_cgi.

- Perrin




-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Jean-Michel Hiver <jh...@mkdoc.com>.
>Didn't Geoff already answer this question for you?  You can't do this in
>this way with PerlSendHeader turned on.  I'm not sure if your goal here
>is to send your own custom 404 error or to have apache pick it up and
>send the ErrorDocument without your content. If you explain what you're
>trying to accomplish, maybe we can suggest a better way.
>  
>
Hi Perrin,

Yes, what I'm trying to achieve is get Apache::Registry to send custom 
404 pages - just like under mod_cgi.

Cheers,
Jean-Michel.

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [BUG] Apache::Registry / 404 Not Found

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2004-03-15 at 08:11, Jean-Michel Hiver wrote:
> The following CGI script:
> 
>     print <<EOF;
>     Status: 404 Not Found
>     Content-Type: text/plain
> 
>     Document not found
>     EOF
[...]
> i.e. the Apache ErrorDocument is appended to the response.

Didn't Geoff already answer this question for you?  You can't do this in
this way with PerlSendHeader turned on.  I'm not sure if your goal here
is to send your own custom 404 error or to have apache pick it up and
send the ErrorDocument without your content.  If you explain what you're
trying to accomplish, maybe we can suggest a better way.

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html