You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Julio Carlos Barrera Juez <ju...@gmail.com> on 2012/05/10 12:25:09 UTC

Re: about setting r->headers_out

Hi!

I have the same problem than you, Rui Hu. I have an output filter that
changes the body of the response, but then "content-type" header is
changed to "text/plain", and I want to maintain the original
"text/html".

I have tried to use:

apr_table_set(r->headers_out, "Content-Type", "text/html");

but it doesn't work.

Can you show me what is your solution "hook handler"? I have only an
input filter and an output filter in my module. I only change the
request_rec filename to use other file on disk.


Thank you!!

>Thanks!
>
>I tried to hook "handler" and it works well.
>
>Rui Hu
>
>2012/2/29 Sorin Manolache <so...@gmail.com>
>
> On 02/29/12 07:52, Rui Hu wrote:
>
>> hi,
>>
>> I want to set "Content-Type" and "Cache-Control" fields in my private
>> module. So I hooked fixups and used apr_table_setn to set
>> r->headers_out but nothing happened. Was it thought through?
>>
>> Thanks for you help!
>>
>
> Try to set r->err_headers_out.
>
> For content-type you could check the configuration directive DefaultType.
>
> You could also set Cache-Control with the Headers directive. Check its
> "always" option too.
>
> You can also combine the Headers directive with environment variables set
> in r->subprocess_env. Check http://httpd.apache.org/docs/**
> 2.0/mod/mod_headers.html#**header<http://httpd.apache.org/docs/2.0/mod/mod_headers.html#header>
>
> Regards,
> Sorin
>
>
>
>
>--
>Best regards,
>
>Rui Hu
>----------------------------------------------------------------------------------------
>State Key Laboratory of Networking & Switching Technology
>Beijing University of Posts and Telecommunications(BUPT)
>MSN: tchrbupt@gmail.com
>-----------------------------------------------------------------------------------------

Re: about setting r->headers_out

Posted by Julio Carlos Barrera Juez <ju...@gmail.com>.
It worked for me! Thank you very much! I don't know why, but I was
thinking this method changes the request "Content-Type", not the
response one (it has no sense at all, sorry).

Thank you very much Daniel! You solved my issue in 5 secs!

Regards, Juilo.

On 10 May 2012 12:36, Daniel Gruno <ru...@cord.dk> wrote:
> On 10-05-2012 12:25, Julio Carlos Barrera Juez wrote:
>> Hi!
>>
>> I have the same problem than you, Rui Hu. I have an output filter that
>> changes the body of the response, but then "content-type" header is
>> changed to "text/plain", and I want to maintain the original
>> "text/html".
>>
>> I have tried to use:
>>
>> apr_table_set(r->headers_out, "Content-Type", "text/html");
>>
>> but it doesn't work.
>>
>> Can you show me what is your solution "hook handler"? I have only an
>> input filter and an output filter in my module. I only change the
>> request_rec filename to use other file on disk.
>
> Have you tried using ap_set_content_type(r, "text/html") instead?
> I noticed that in its description, it says:
>
> "This function must be called to set r->content_type in order for the
> AddOutputFilterByType directive to work correctly.", so it may be
> related to your problem.
>
> With regards,
> Daniel.

Re: about setting r->headers_out

Posted by Daniel Gruno <ru...@cord.dk>.
On 05/10/2012 06:39 PM, Nick Kew wrote:
>> "This function must be called to set r->content_type in order for the
>> AddOutputFilterByType directive to work correctly.", so it may be
>> related to your problem.
>
> Whoops!  That's no longer true since AddOutputFilterByType moved
> to mod_filter.  Where do the docs still say that?
>
>

Well the docs probably don't mention it, but the header file still does: 
http_protocol.h (for 2.4.x) says:
------------------------
/**
  * Set the content type for this request (r->content_type).
  * @param r The current request
  * @param ct The new content type
  * @warning This function must be called to set r->content_type in order
  * for the AddOutputFilterByType directive to work correctly.
  */
AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct);
------------------------

With regards,
Daniel.

Re: about setting r->headers_out

Posted by Nick Kew <ni...@apache.org>.
On Thu, 10 May 2012 12:36:54 +0200
Daniel Gruno <ru...@cord.dk> wrote:

> On 10-05-2012 12:25, Julio Carlos Barrera Juez wrote:
> > Hi!
> > 
> > I have the same problem than you, Rui Hu. I have an output filter that
> > changes the body of the response, but then "content-type" header is
> > changed to "text/plain", and I want to maintain the original
> > "text/html".

Erm, that doesn't sound like an original anything.  More like
the core inserting a default type when none was set.

> Have you tried using ap_set_content_type(r, "text/html") instead?
> I noticed that in its description, it says:

That should be the usual solution.

> "This function must be called to set r->content_type in order for the
> AddOutputFilterByType directive to work correctly.", so it may be
> related to your problem.

Whoops!  That's no longer true since AddOutputFilterByType moved
to mod_filter.  Where do the docs still say that?


-- 
Nick Kew

Re: about setting r->headers_out

Posted by Daniel Gruno <ru...@cord.dk>.
On 10-05-2012 12:25, Julio Carlos Barrera Juez wrote:
> Hi!
> 
> I have the same problem than you, Rui Hu. I have an output filter that
> changes the body of the response, but then "content-type" header is
> changed to "text/plain", and I want to maintain the original
> "text/html".
> 
> I have tried to use:
> 
> apr_table_set(r->headers_out, "Content-Type", "text/html");
> 
> but it doesn't work.
> 
> Can you show me what is your solution "hook handler"? I have only an
> input filter and an output filter in my module. I only change the
> request_rec filename to use other file on disk.

Have you tried using ap_set_content_type(r, "text/html") instead?
I noticed that in its description, it says:

"This function must be called to set r->content_type in order for the
AddOutputFilterByType directive to work correctly.", so it may be
related to your problem.

With regards,
Daniel.