You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "John D.Lima" <li...@5cats.org> on 2004/03/31 19:31:36 UTC

[mp2] custom_response() in HTTP Request Output Filters?

I have a proxy running with mod_proxy with a request output filter for 
examining
the (remote) server response.  Under certain conditions I want to add 
additional
html to the server's error response, or replace a (possibly non-error) 
response
with a dynamic error document of my construction, changed status 
included.

It'd be great if I could grab the filter's request and let
$r->custom_response() do what I want, possibly adding an EOS bucket to
the filter stream before passing the brigade on at the end of the 
filter handler.

This seems related to a someone's previous thread titled,
"[mp2] $r->status does not accept a valid parameter" where the issue was
how to change the $r->status, apparently in the response phase.  But 
I'm past
that, in the (request) output filter.

Cheers,
-jd.


-- 
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: [mp2] custom_response() in HTTP Request Output Filters?

Posted by Stas Bekman <st...@stason.org>.
John D.Lima wrote:
[...]
> I was rather hoping to avoid setting up the logic to examine bucket 
> contents.
> Reading between the line [sic] I guess the answer is no, 
> $r->custom_response
> doesn't work in the request output filter?
> 
> Does the connection filter give me access to the $r->headers_out() as well?
> In my case, I'm reporting (to the client) an error page when the server 
> fails
> to set a particular HTTP response header.   I want to do something with 
> that
> header value, possibly sending an error page on to the client.  With the 
> request
> filter, I just $xyz = $f->r->headers_out{'XYZ'} and go on.

Once you are outside (post) the response phase, you can't use its comfy API, 
because the request has been sent already. In the connection filter you have 
an access to the raw HTTP headers and the response body.

> Seems you have an excellent example for this in your recent 
> -FixupHeaders package
> and other tuts.  I'll forge ahead with using the bucket code.

Good ;)

__________________________________________________________________
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: [mp2] custom_response() in HTTP Request Output Filters?

Posted by "John D.Lima" <li...@5cats.org>.
On Mar 31, 2004, at 10:04 AM, Stas Bekman wrote:

> John D.Lima wrote:
>> I have a proxy running with mod_proxy with a request output filter 
>> for examining
>> the (remote) server response.  Under certain conditions I want to add 
>> additional
>> html to the server's error response, or replace a (possibly 
>> non-error) response
>> with a dynamic error document of my construction, changed status 
>> included.
>> It'd be great if I could grab the filter's request and let
>> $r->custom_response() do what I want, possibly adding an EOS bucket to
>> the filter stream before passing the brigade on at the end of the 
>> filter handler.
>> This seems related to a someone's previous thread titled,
>> "[mp2] $r->status does not accept a valid parameter" where the issue 
>> was
>> how to change the $r->status, apparently in the response phase.  But 
>> I'm past
>> that, in the (request) output filter.
>
> i.e. you want to be able to change the response headers in addition to 
> the response body. in which case you must use a connection output 
> filter.

Well, sure, when you put it that way ;)

I was rather hoping to avoid setting up the logic to examine bucket 
contents.
Reading between the line [sic] I guess the answer is no, 
$r->custom_response
doesn't work in the request output filter?

Does the connection filter give me access to the $r->headers_out() as 
well?
In my case, I'm reporting (to the client) an error page when the server 
fails
to set a particular HTTP response header.   I want to do something with 
that
header value, possibly sending an error page on to the client.  With 
the request
filter, I just $xyz = $f->r->headers_out{'XYZ'} and go on.

Seems you have an excellent example for this in your recent 
-FixupHeaders package
and other tuts.  I'll forge ahead with using the bucket code.

Cheers,
-jd.


-- 
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: [mp2] custom_response() in HTTP Request Output Filters?

Posted by Stas Bekman <st...@stason.org>.
John D.Lima wrote:
> I have a proxy running with mod_proxy with a request output filter for 
> examining
> the (remote) server response.  Under certain conditions I want to add 
> additional
> html to the server's error response, or replace a (possibly non-error) 
> response
> with a dynamic error document of my construction, changed status included.
> 
> It'd be great if I could grab the filter's request and let
> $r->custom_response() do what I want, possibly adding an EOS bucket to
> the filter stream before passing the brigade on at the end of the filter 
> handler.
> 
> This seems related to a someone's previous thread titled,
> "[mp2] $r->status does not accept a valid parameter" where the issue was
> how to change the $r->status, apparently in the response phase.  But I'm 
> past
> that, in the (request) output filter.

i.e. you want to be able to change the response headers in addition to the 
response body. in which case you must use a connection output filter.


-- 
__________________________________________________________________
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: [mp2] custom_response() in HTTP Request Output Filters?

Posted by "John D.Lima" <li...@5cats.org>.
On Mar 31, 2004, at 11:46 AM, Geoffrey Young wrote:

>
>>>> Under certain conditions I want to add
>>>> additional
>>>> html to the server's error response
>
>>
>> But John is talking about converting a non-error response into an 
>> error.
>> Does it still apply?
>
> I don't know.  it was the above quoted part that caught my attention, 
> but it
> may not solve all of what john wants to do.
>
> nevertheless, there's no way to know for sure until we open up that 
> hook,
> and the timeline for that depends on our available tuits, which aren't 
> all
> that plentiful at the moment...

This sounds pretty promising.  I'll put a todo in my code to check on 
it,
and in the meantime polish up my (err, Stas') connection filter code.
Man you guys are *fast* !

Cheers,
-jd.

Re: [mp2] custom_response() in HTTP Request Output Filters?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>> Under certain conditions I want to add
>>> additional
>>> html to the server's error response

> 
> But John is talking about converting a non-error response into an error.
> Does it still apply?

I don't know.  it was the above quoted part that caught my attention, but it
may not solve all of what john wants to do.

nevertheless, there's no way to know for sure until we open up that hook,
and the timeline for that depends on our available tuits, which aren't all
that plentiful at the moment...

--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: [mp2] custom_response() in HTTP Request Output Filters?

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> 
> John D.Lima wrote:
> 
>>I have a proxy running with mod_proxy with a request output filter for
>>examining
>>the (remote) server response.  Under certain conditions I want to add
>>additional
>>html to the server's error response, or replace a (possibly non-error)
>>response
>>with a dynamic error document of my construction, changed status included.
>>
>>It'd be great if I could grab the filter's request and let
>>$r->custom_response() do what I want, possibly adding an EOS bucket to
>>the filter stream before passing the brigade on at the end of the filter
>>handler.
> 
> 
> I think the insert_error_filter hook introduced in 2.0.49 will do exactly
> what you want, but unfortunately mod_perl hasn't added the glue for this yet
> so we can't know for sure.
> 
> something to add to the todo list I suppose.

But John is talking about converting a non-error response into an error. Does 
it still apply?

__________________________________________________________________
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: [mp2] custom_response() in HTTP Request Output Filters?

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

John D.Lima wrote:
> I have a proxy running with mod_proxy with a request output filter for
> examining
> the (remote) server response.  Under certain conditions I want to add
> additional
> html to the server's error response, or replace a (possibly non-error)
> response
> with a dynamic error document of my construction, changed status included.
> 
> It'd be great if I could grab the filter's request and let
> $r->custom_response() do what I want, possibly adding an EOS bucket to
> the filter stream before passing the brigade on at the end of the filter
> handler.

I think the insert_error_filter hook introduced in 2.0.49 will do exactly
what you want, but unfortunately mod_perl hasn't added the glue for this yet
so we can't know for sure.

something to add to the todo list I suppose.

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