You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Geoffrey Young <ge...@modperlcookbook.org> on 2004/06/05 23:41:44 UTC

Re: Apache::Registry HEAD request also return document body

cc'ing the modperl list for the benefit of all

Bruno De Fraine wrote:
> Hello Geoffrey,
> 
> I'm having a problem with my server (Apache/1.3.29 (Debian GNU/Linux)
> mod_perl/1.29) that got raised on the mod_perl list in 2001:
> Apache::Registry HEAD request also return document body
> http://gossamer-threads.com/lists/modperl/modperl/43829

yeah, it's broken.

> 
> [And although it's considered harmless there, it is actually causing
> data corruption with Mozilla, see
> http://bugzilla.mozilla.org/show_bug.cgi?id=245447 if you're interested.]

wow, a HEAD request in the wild.  nice.

> 
> I'm writing you because you were one of the major contributors to an
> answer. The most complete fix I could find of you is here: [RFC]
> Apache::HEADRegistry
> http://mathforum.org/epigone/modperl/starfaxbi
> But at that date you considered it RFC alphaware. 

I tend to put the alphaware disclaimer on just about everything I write ;)

> Before I go ahead with
> that one, I want to ask if there is anything more recent, and if you got
> any important feedback.

not really.  IIRC I went a few rounds with one of the folks from the thread
in private, trying to tweak HEADRegistry to work in all circumstances.  also
IIRC the current implementation still falls short in one category, but I
can't recall which one it is.  good thing there's the start of a test suite
(though I doubt it works due to lots of changes in Apache-Test since then).

but other than the test suite, though, there is no reason why it shouldn't
work under most circumstances (with the caveat that I haven't even looked at
that code in maybe two years).  just keep in mind that HEADRegistry uses
Apache::RegistryNG, not Apache::Registry, so there may be slight differences
in the behavior of normal scripts.

> Also, out of curiousity, why is there apparantly no interest in the main
> mod_perl distribution to get this fixed in the default behaviour of
> mod_perl or at least Apache::Registry?

again from memory, but I think it's more difficult to solve in
Apache::Registry than it first appears - the logic that controls this aspect
of Registry is actually in mod_perl core and fairly complex.  there are also
aspects of legacy CGI.pm that call the code in question that make it
difficult to fix the problem under all circumstances.  however, the largest
obstacle is that playing around with long-standing code in the stable (1.0)
mod_perl branch is kind of asking for trouble - I would be (and was) afraid
that fixing this smallish problem in core would cause more harm than good
for others.  yeah, I know that sounds not so great, but...

that said, I am certainly willing to look (again) into fixing core so that
Registry and CGI.pm behave properly.  in the meanwhile, if you give me until
the start of the week I will adjust Apache::HEADRegistry so that the test
suite is functional and review the code so we can begin to explore if that
module is a real option for you.

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: Apache::Registry HEAD request also return document body

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>>[And although it's considered harmless there, it is actually causing
>>>data corruption with Mozilla, see
>>>http://bugzilla.mozilla.org/show_bug.cgi?id=245447 if you're interested.]
>>
>>wow, a HEAD request in the wild.  nice.
> 
> 
> Just for general information, mozilla (and browsers based upon it)
> always do a HEAD before a GET if the user does a right-mouse-click
> menu "Save Link Target As..." or does a "Save Page As...". This
> recently caused me headaches with some of my mod_perl scripts that
> were returning broken responses to the HEAD request. 

along the same lines, I would think this is really a bug on both sides, and
that the INVALID status of that bug report is wrong.

certainly servers should be producing the proper response to a HEAD request,
 but clients should be more intelligent about things as well in the - HEAD
requests are often mis-implemented, either with minor differences like the
headers not really matching an identical GET request (very common), or just
simply making GET and HEAD equivalent (like Registry mistakenly does in
mp1).  and it's not just little guys who are getting it wrong either:

$ telnet www.yahoo.com 80
Trying 216.109.117.207...
Connected to www.yahoo.com (216.109.117.207).
Escape character is '^]'.
HEAD / HTTP/1.1
host: www.yahoo.com

HTTP/1.1 200 OK
Date: Sun, 06 Jun 2004 08:15:39 GMT
P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM
DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND
PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
Cache-Control: private
Vary: User-Agent
Connection: close
Content-Type: text/html

<html><head>

<title>Yahoo!</title>...


--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: Apache::Registry HEAD request also return document body

Posted by Stephen Quinney <st...@computing-services.oxford.ac.uk>.
On Sat, Jun 05, 2004 at 05:41:44PM -0400, Geoffrey Young wrote:
> cc'ing the modperl list for the benefit of all
> 
> Bruno De Fraine wrote:
> > Hello Geoffrey,
> > 
> > I'm having a problem with my server (Apache/1.3.29 (Debian GNU/Linux)
> > mod_perl/1.29) that got raised on the mod_perl list in 2001:
> > Apache::Registry HEAD request also return document body
> > http://gossamer-threads.com/lists/modperl/modperl/43829
> 
> yeah, it's broken.
> 
> > 
> > [And although it's considered harmless there, it is actually causing
> > data corruption with Mozilla, see
> > http://bugzilla.mozilla.org/show_bug.cgi?id=245447 if you're interested.]
> 
> wow, a HEAD request in the wild.  nice.

Just for general information, mozilla (and browsers based upon it)
always do a HEAD before a GET if the user does a right-mouse-click
menu "Save Link Target As..." or does a "Save Page As...". This
recently caused me headaches with some of my mod_perl scripts that
were returning broken responses to the HEAD request. 

Stephen Quinney


-- 
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: Apache::Registry HEAD request also return document body

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> cc'ing the modperl list for the benefit of all
> 
> Bruno De Fraine wrote:
> 
>>Hello Geoffrey,
>>
>>I'm having a problem with my server (Apache/1.3.29 (Debian GNU/Linux)
>>mod_perl/1.29) that got raised on the mod_perl list in 2001:
>>Apache::Registry HEAD request also return document body
>>http://gossamer-threads.com/lists/modperl/modperl/43829
> 
> 
> yeah, it's broken.

I'm not sure if that an option, but another solution is to move to mod_perl 
2.0, since Apache 2.0 handles HEAD requests properly on its own and requires 
no extra work from mod_perl handlers.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
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: Apache::Registry HEAD request also return document body

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
cc'ing the modperl list

> I tested the new module and basicly it seems to works fine with my
> application. However you overlooked something obvious in your
> implementation.
> 
> The problem occurs when trying to download a binary attachment. This
> produced server errors:
> 
> [Tue Jun  8 18:38:14 2004] [error] Can't locate object method "BINMODE"
> via package "Apache::HEADRegistry" at /home/santa/cgi-test/script.pl
> line 20.

are you running on windows?  the only time I have ever seen binmode required
is for win32.

> 
> From the error, you'll obviously directly see what is missing and this
> was the way I fixed it:

[snip]

well, in Apache.xs BINMODE is a no-op, so I have coded it that way and it
seems to work just the same.  let me know if it works for you.

> This example works fine after applying the above patch. Before it did not.

ok, an updated version is here:
  http://www.modperlcookbook.org/~geoff/modules/Apache-HEADRegistry-0.01.tar.gz

> 
> Notice that I also fixed the PRINTF (however I didn't test it), because
> sooner or later a CGI script is gone use a printf-statement and that
> would break. 

yeah, well, there is write() too :)  but I've incorporated a PRINTF
implementation, so we're covered there - write() is far less common and can
be added later.

> I made me the OO-guy in me think however, that what we're
> doing might not be the most elegant/robust solution. The "Apache" module
> itself is already used to be tied to STDOUT. It already appropriately
> implements BINMODE, PRINT, etc. It therefore seems to make sense to also
> tie something to STDOUT that is a subclass of the Apache class (but that
> overides the PRINT method however by a method that conditionally invokes
> $self->SUPER::PRINT). Then we wouldn't have to write "adaptor"-methods
> like the BINMODE from my patch.
> One approach might be to make Apache::HEADRegistry mutli-inheret from
> Apache::RegistryNG as well as Apache. Or to tie not the
> Apache::HEADRegistry class itself to STDOUT, but a helper class that is
> an Apache subclass.

well, the Apache class (and it's write operations) _are_ the problem -
outside of BINMODE (and a handful of others that aren't relevant, like TELL)
the write-based TIEHANDLE functions in Apache.xs need to be intercepted and
made HEAD compliant.  so, there is really little that we could reuse from
the Apache class.

and taking this approach is the path of least resistance - it's already
mostly done :)

> 
> What do you think? You will certainly have a lot more perltie and mod_perl
> experience than I do, so this might be obviously a bad idea for some
> reason.

well, I think you're on the right track adding BINMODE and PRINTF.  give the
latest version a whirl and let me know.

and thanks for your feedback and effort!

--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: Apache::Registry HEAD request also return document body

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

Geoffrey Young wrote:
> in the meanwhile, if you give me until
> the start of the week I will adjust Apache::HEADRegistry so that the test
> suite is functional and review the code so we can begin to explore if that
> module is a real option for you.

ok, I've updated the tests and reviewed the code in Apache::HEADRegistry.
you can find it here:

http://www.modperlcookbook.org/~geoff/modules/Apache-HEADRegistry-0.01.tar.gz

with the exception of redirect responses (which there is really no way to
fix via an extension like this) I think it looks ok.  at least ok enough for
you to test on your own.  if the tests do not accurately reflect the kind of
interface you are using in your scripts, please feel free to add a short
test that mimics your approach and I'll integrate it.  please note that the
goal in this module is to fix HEAD requests a la mod_cgi emulation - if
you're using the mod_perl API ($r, etc) in your Registry scripts then you
don't need this since you can just check $r->header_only yourself.

if things look good, I'll make it official and upload to CPAN.

--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