Re: ignore header_only()?

2000-08-07 Thread Dan Rench

On Fri, 4 Aug 2000, Vivek Khera wrote:

> > "NT" == Nathan Torkington <[EMAIL PROTECTED]> writes:
> 
> NT> I see some programmers don't check header_only().  Are there
> NT> bad things in store if you don't?  Or will Apache or the browser
> NT> simply ignore the body that gets created?
> 
> My experience is apache just tosses the body for you.  The programmer
> check is mainly an optimization from where I sit.

No, apache will send a body if you generate it even if the client just
sends a HEAD request.  Example:

Head.pm:

package Head;

use strict;
use Apache::Constants 'OK';

sub handler {
my $r = shift; $r->content_type('text/plain'); $r->send_http_header;
print 'header_only() is ', ($r->header_only) ? "true\n" : "false\n";
return OK;
}
1;


httpd.conf:
===
LoadModule mime_modulelibexec/mod_mime.so
ClearModuleList
AddModule mod_mime.c
AddModule mod_so.c
AddModule mod_perl.c
SetHandler perl-script
PerlHandler Head

$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
HEAD / HTTP/1.0

HTTP/1.1 200 OK
Date: Mon, 07 Aug 2000 17:17:47 GMT
Server: Apache/1.3.12 (Unix) mod_perl/1.24
Connection: close
Content-Type: text/plain

header_only() is true
Connection closed by foreign host.
$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Mon, 07 Aug 2000 17:17:52 GMT
Server: Apache/1.3.12 (Unix) mod_perl/1.24
Connection: close
Content-Type: text/plain

header_only() is false
Connection closed by foreign host.


A mod_proxy ProxyPass frontend will discard the body if given a "HEAD"
request though.




Re: ignore header_only()?

2000-08-05 Thread Ken Fox

Ken Williams wrote:
> I know it was ages ago when you sent this patch, but what's the
> rationale for having $r->sent_header() return 1 when it hasn't sent the
> header?

I didn't want to break anything. I'm hoping that people using sent_header
are just checking for true, not for 1. (That's the way the mod_perl core
does it.)

> Shouldn't it be fixed to return 1 or 0 according to whether the
> header has actually been sent?

I'll let Doug decide. IMHO sent_header is the wrong method name. The current
function should be called need_headers. (When PerlSendHeader is on, you don't
need to send headers.) A new function should be added to let you know if the
headers have already been sent.

> If need be, perhaps it could distinguish like this:
> 
>undef - headers have not been sent (PerlSendHeader on)
>0 - headers have not been sent (PerlSendHeader off)
>1 - headers have already been sent (PerlSendHeader off)
>2 - headers have already been sent (PerlSendHeader on)

That might break code because you're changing the truth values. My code
didn't need to differentiate between the two unsent cases which is why
I'm only returning 3 different values.

- Ken



Re: ignore header_only()?

2000-08-05 Thread Ken Williams

Ken Fox wrote:
> I was using $request->sent_header and found out that it's
> not terribly useful if PerlSendHeader is off -- sent_header
> always returns 1. I changed mod_perl_sent_header so that
> it returns 0, 1 or 2:
> 
>   0 - headers have not been sent (PerlSendHeader on)
>   1 - headers have not been sent (PerlSendHeader off)
>   2 - headers have already been sent

I know it was ages ago when you sent this patch, but what's the
rationale for having $r->sent_header() return 1 when it hasn't sent the
header?  Shouldn't it be fixed to return 1 or 0 according to whether the
header has actually been sent?  

If need be, perhaps it could distinguish like this:

   undef - headers have not been sent (PerlSendHeader on)
   0 - headers have not been sent (PerlSendHeader off)
   1 - headers have already been sent (PerlSendHeader off)
   2 - headers have already been sent (PerlSendHeader on)

But I'd rather just have it return 1 or 0, and have a seperate method
that tells you whether PerlSendHeader is on or off.






Re: ignore header_only()?

2000-08-05 Thread Eric Cholet

> Ken Fox wrote:
> > I was using $request->sent_header and found out that it's
> > not terribly useful if PerlSendHeader is off -- sent_header
> > always returns 1. I changed mod_perl_sent_header so that
> > it returns 0, 1 or 2:
> > 
> >   0 - headers have not been sent (PerlSendHeader on)
> >   1 - headers have not been sent (PerlSendHeader off)
> >   2 - headers have already been sent
> 
> Is this the right list for change proposals? Should I re-submit my
> patch?

Yes it's the right list, and no, no need to resubmit. Personally I only
commit bug fixes, and Doug looks at new features. He'll get around to it,
he's just a bit busy at the moment. 

Thanks,
--
Eric





Re: ignore header_only()?

2000-08-05 Thread Matt Sergeant

On Fri, 4 Aug 2000, Ken Fox wrote:

> > I was using $request->sent_header and found out that it's
> > not terribly useful if PerlSendHeader is off -- sent_header
> > always returns 1. I changed mod_perl_sent_header so that
> > it returns 0, 1 or 2:
> > 
> >   0 - headers have not been sent (PerlSendHeader on)
> >   1 - headers have not been sent (PerlSendHeader off)
> >   2 - headers have already been sent

I do that sort of thing for AxKit, overriding the Apache class and
re-blessing $r, and implementing a safer send_http_header() that remembers
if the headers have already been sent.

-- 


Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




Re: ignore header_only()?

2000-08-04 Thread Jeremy Howard

Ken Fox said:

> Sorry to be a pain, but I still haven't heard anything back about my
> proposal:
>
> Ken Fox wrote:
> > I was using $request->sent_header and found out that it's
> > not terribly useful if PerlSendHeader is off -- sent_header
> > always returns 1. I changed mod_perl_sent_header so that
> > it returns 0, 1 or 2:
> >
> >   0 - headers have not been sent (PerlSendHeader on)
> >   1 - headers have not been sent (PerlSendHeader off)
> >   2 - headers have already been sent
>
> Is this the right list for change proposals? Should I re-submit my
> patch?
>
You could try:

The dev list is for discussions about the development of the core mod_perl
modules.

Subscription information.

  a.. subscribe to the list: [EMAIL PROTECTED]
  b.. unsubscribe from the list: [EMAIL PROTECTED]
  c.. get help with the list: [EMAIL PROTECTED]

Doug popped his head up a few weeks ago to say he's in read-only mode at the
moment. I don't know why--maybe he's busy with v2 at the moment. If you
don't have any luck on the dev list you could try mailing him directly, I
guess.

--
  Jeremy Howard
  [EMAIL PROTECTED]




Re: ignore header_only()?

2000-08-04 Thread Ken Fox

Ajit Deshpande wrote:
> On Fri, Aug 04, 2000 at 04:22:29PM -0600, Nathan Torkington wrote:
> > Thanks for the speedy response.  You've now emboldened me to ask my
> > second question: sometimes I see people not calling send_http_header()
> > and yet their HTML still comes through.  Does mod_perl sometimes
> > automatically call this for you?
> 
> Yep, its a configurable option.
> 
> http://perl.apache.org/guide/config.html:
> 
>PerlSendHeader On

Sometimes I've seen people be really careful and use sent_header() to
test if the headers have already been sent. But that only works with
PerlSendHeader turned on...

Sorry to be a pain, but I still haven't heard anything back about my
proposal:

Ken Fox wrote:
> I was using $request->sent_header and found out that it's
> not terribly useful if PerlSendHeader is off -- sent_header
> always returns 1. I changed mod_perl_sent_header so that
> it returns 0, 1 or 2:
> 
>   0 - headers have not been sent (PerlSendHeader on)
>   1 - headers have not been sent (PerlSendHeader off)
>   2 - headers have already been sent

Is this the right list for change proposals? Should I re-submit my
patch?

- Ken



Re: ignore header_only()?

2000-08-04 Thread Ajit Deshpande

On Fri, Aug 04, 2000 at 04:22:29PM -0600, Nathan Torkington wrote:
> Thanks for the speedy response.  You've now emboldened me to ask my
> second question: sometimes I see people not calling send_http_header()
> and yet their HTML still comes through.  Does mod_perl sometimes
> automatically call this for you?

Yep, its a configurable option. 

http://perl.apache.org/guide/config.html:

   [..]

   PerlSendHeader On

   PerlSendHeader On tells the server to send an HTTP header to the
   browser on every script invocation. You will want to turn this off for
   nph (non-parsed-headers) scripts.

   The PerlSendHeader On setting invokes ap_send_http_header() after 
   parsing your script headers. It is only meant for CGI emulation, and  
   to send the HTTP header it's always better either to use $q->header   
   from the CGI.pm module or to use $r->send_http_header using the Apache
   Perl API.

   [..]

Ajit



Re: ignore header_only()?

2000-08-04 Thread Nathan Torkington

Thanks for the speedy response.  You've now emboldened me to ask my
second question: sometimes I see people not calling send_http_header()
and yet their HTML still comes through.  Does mod_perl sometimes
automatically call this for you?

Nat



Re: ignore header_only()?

2000-08-04 Thread Vivek Khera

> "NT" == Nathan Torkington <[EMAIL PROTECTED]> writes:

NT> I see some programmers don't check header_only().  Are there
NT> bad things in store if you don't?  Or will Apache or the browser
NT> simply ignore the body that gets created?

My experience is apache just tosses the body for you.  The programmer
check is mainly an optimization from where I sit.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.Khera Communications, Inc.
Internet: [EMAIL PROTECTED]   Rockville, MD   +1-301-545-6996
GPG & MIME spoken herehttp://www.khera.org/~vivek/