Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

How to set Content-type properly

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


aw at ice-sa

May 28, 2011, 5:23 AM

Post #1 of 3 (712 views)
Permalink
How to set Content-type properly

Hi.

I am using :
Apache/2.2.9 (Debian) DAV/2 SVN/1.5.1 mod_jk/1.2.26 PHP/5.2.6-1+lenny9 with Suhosin-Patch
mod_ssl/2.2.9 OpenSSL/0.9.8g mod_apreq2-20051231/2.6.0 mod_perl/2.0.4 Perl/v5.10.0

In a PerlResponseHandler, I am using Template-Toolkit to generate html pages sent back to
the browser.
Before rendering a template, I set the response Content-type header, as :

$r->content_type('text/html');

This results in a HTTP response to the browser, with the following header :

Content-Type: text/html

However, I would like this :

Content-Type: text/html; charset=UTF-8

How do I do that ?

is

$r->content_type('text/html; charset=UTF-8');

admissible ?


joe_schaefer at yahoo

May 28, 2011, 5:27 AM

Post #2 of 3 (701 views)
Permalink
Re: How to set Content-type properly [In reply to]

Yes!



----- Original Message ----
> From: André Warnier <aw [at] ice-sa>
> To: mod_perl list <modperl [at] perl>
> Sent: Sat, May 28, 2011 8:23:34 AM
> Subject: How to set Content-type properly
>
> Hi.
>
> I am using :
> Apache/2.2.9 (Debian) DAV/2 SVN/1.5.1 mod_jk/1.2.26 PHP/5.2.6-1+lenny9 with
>Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g mod_apreq2-20051231/2.6.0
>mod_perl/2.0.4 Perl/v5.10.0
>
> In a PerlResponseHandler, I am using Template-Toolkit to generate html pages
>sent back to the browser.
> Before rendering a template, I set the response Content-type header, as :
>
> $r->content_type('text/html');
>
> This results in a HTTP response to the browser, with the following header :
>
> Content-Type: text/html
>
> However, I would like this :
>
> Content-Type: text/html; charset=UTF-8
>
> How do I do that ?
>
> is
>
> $r->content_type('text/html; charset=UTF-8');
>
> admissible ?
>
>
>
>


aw at ice-sa

May 28, 2011, 6:59 AM

Post #3 of 3 (707 views)
Permalink
Re: How to set Content-type properly [In reply to]

Thank you.

May I suggest a slight improvement in the online doc at
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_content_type_
then, to add this explicitly ?
Currently, it says :

quote

content_type

Get/set the HTTP response Content-type header value.

my $content_type = $r->content_type();
my $prev_content_type = $r->content_type($new_content_type);

* obj: $r ( Apache2::RequestRec object )
* opt arg1: $new_content_type (MIME type string)

Assign a new HTTP response content-type. It will affect the response only if HTTP
headers weren't sent yet.
* ret: $content_type

The current content-type value.

If $new_content_type was passed, the previous value is returned instead.
* since: 2.0.00

For example, set the Content-type header to text/plain.

$r->content_type('text/plain');

If you set this header via the headers_out table directly, it will be ignored by Apache.
So do not do that.

unquote

Maybe just an additional example :

$r->content_type('text/plain; charset=UTF-8');



Joe Schaefer wrote:
> Yes!
>
>
>
> ----- Original Message ----
>> From: André Warnier <aw [at] ice-sa>
>> To: mod_perl list <modperl [at] perl>
>> Sent: Sat, May 28, 2011 8:23:34 AM
>> Subject: How to set Content-type properly
>>
>> Hi.
>>
>> I am using :
>> Apache/2.2.9 (Debian) DAV/2 SVN/1.5.1 mod_jk/1.2.26 PHP/5.2.6-1+lenny9 with
>> Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g mod_apreq2-20051231/2.6.0
>> mod_perl/2.0.4 Perl/v5.10.0
>>
>> In a PerlResponseHandler, I am using Template-Toolkit to generate html pages
>> sent back to the browser.
>> Before rendering a template, I set the response Content-type header, as :
>>
>> $r->content_type('text/html');
>>
>> This results in a HTTP response to the browser, with the following header :
>>
>> Content-Type: text/html
>>
>> However, I would like this :
>>
>> Content-Type: text/html; charset=UTF-8
>>
>> How do I do that ?
>>
>> is
>>
>> $r->content_type('text/html; charset=UTF-8');
>>
>> admissible ?
>>
>>
>>
>>
>

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.