http headers with CGI.pm and mod_perl (bug?)
From: Elie W (welie_at_yahoo.com)
Date: 11/10/04
- Next message: John Bokma: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Previous message: Brian McCauley: "Re: Exporting dependency methods"
- Next in thread: John Bokma: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Reply: John Bokma: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Reply: Gunnar Hjalmarsson: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 10 Nov 2004 21:19:30 +0200
I have a question about printing http headers with CGI.pm running on an
Apache server with mod_perl. What happens if I need to change the http
header after I already called $query->header? Is there a way to prevent
CGI from sending the header to mod_perl?
According to the documentation of CGI, to print a header I would do:
print $query->header;
My assumption is, that $query->header; returns a string, so I could do:
$header=$query->header;
However, a quick look under the hood shows that when mod_perl is running
on the server, $query->header does not actually return anything, rather
it uses a call to mod_perl to print the header.
This being the case, I have the following problem, where I need to
reprint an http header.
I have a subroutine called webify which is supposed to take some text
and wrap it up in html. In the subroutine some other routines may be
called to massage the text a bit. Becuase it is possible that those
routines may fail, I put the call to webify inside an eval. If anything
fails, I want to default to printing the plain text.
$finalHTML = eval {webify(text)};
if ($@){
do alternate....
$query->header(-type=>'text/plain'); #or whatever the type for plain
text is
}
In the routine I do:
sub webify {
....
$output=$query->header(-type=>'text/html');
$output.=$query->h1(getUser($user));
....
}
Suppose getUser dies, and therefore the "do alternate...." above is
executed. Well, the call to $query->header in webify() has already sent
the header to mod_perl which has printed out the header already and I
believe the 2nd call to $query->header, in the alrenate code, actually
won't do anything.
So what to do? Obviously I can code around it but its not as clean. Is
this the way things are supposed to happen? Is this a bug? Is there a
way to disable sending the header to mod_perl?
Thanks,
Elie.
- Next message: John Bokma: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Previous message: Brian McCauley: "Re: Exporting dependency methods"
- Next in thread: John Bokma: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Reply: John Bokma: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Reply: Gunnar Hjalmarsson: "Re: http headers with CGI.pm and mod_perl (bug?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|