Gossamer Forum
Home : Products : Gossamer Links : Discussions :

change HTTP Response Header

Quote Reply
change HTTP Response Header
Hi,

I am a little lost. About one year ago I changed the code in a test installation to define the charset-type with utf8.
I cannot find the file any more and maybe someone (probably Andy) has a hint for me.
I can set header_charset in Misc. Options but as far as I can see that is for templates.
The idea is to define it in the header
https://gtmetrix.com/...acter-set-early.html

I would have expected to hack /GT/WWW/http/Header.pm -> sub header {

But that does not look like the shortest way, because I have to check if the charset is submitted and change it or if not submitted add $CFG->{header_charset}.

The other - not so short way would be to add -charset => $CFG->{header_charset} to all $IN->header() in Page.pm, Search.pm etc.

Thankful for any input, ideas or the shortest way.

n||i||k||o
Quote Reply
Re: [el noe] change HTTP Response Header In reply to
Hi,

I've always had a bit of fun and games getting the pre-header stuff to work.

Have you tried doing a Dumper, to see what is included in $self?

Code:
sub header {
my $self = shift;

I'm not 100% sure what is passed into that function (without testing). I'm currently suffering from sinusitis, so am not at 100% Blush

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] change HTTP Response Header In reply to
Hi Andy,

changing e.g.

Code:
sub generate_home_page {
# --------------------------------------------------------
# Display the home page.
#
print $IN->header();
print Links::Build::build(home => {});
}

to

Code:
sub generate_home_page {
# --------------------------------------------------------
# Display the home page.
#
print $IN->header(-charset => $CFG->{header_charset});
print Links::Build::build(home => {});
}

works.
Your Dumper hint showed me that I have been hanging around in the wrong sub. I should have been to ./admin/GT/CGI.pm

Code:
# Add the Content-type header.
my $type = @_ == 1 && !ref($_[0]) ? $_[0] : delete($p{-type}) || 'text/html';
my $charset = delete $p{-charset};
if ($charset and $type =~ /^text\// and $type !~ /\bcharset\b/) {
$type .= "; charset=$charset";
}
#++ start new code
# had to use plain text charset because $CFG->{header_charset}
# is not yet defined as far as I can see
elsif ($type =~ /^text\// and $type !~ /\bcharset\b/) {
$type .= "; charset=windows-1252";
}
#++ end new code
push @headers, "Content-type: $type";
This looked more familiar. Now I still cannot remember what I did, but the above works. Not sure if I can cause trouble with that approach.
The first approach seems a little cleaner and maybe the way GT would have taken for an improvement.
What do you think?

Thanks and get well soon!

Niko

Last edited by:

el noe: Oct 10, 2016, 8:54 AM
Quote Reply
Re: [el noe] change HTTP Response Header In reply to
thanks for help
i have seme problem
but now its fixed
pablo from china 22 years old
Quote Reply
Re: [el noe] change HTTP Response Header In reply to
Hi

Glad you got it going. I seem to remember having to do a similar tweak in my install, but I just forced it to accept it on ALL header requests... so:

Code:
my $charset = delete $p{-charset};

I changed to:

Code:
delete $p{-charset}
my $charset = "utf-8" ;

I have not seen any adverse affects on it since that change, so it should be safe to do :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] change HTTP Response Header In reply to
Hi Andy,

Thanks for your feedback. Sounds good and easy.
Having seen your utf8 bit in your example:
I want to switch to utf8 somewhen next year and I am playing around a little since a couple of days.
Could you give me some advice here?

I would make an installation, modify all tables to utf8_general_ci (seems like the right choice but also not sure here)
Make a mysql dump of the old data.
I would download the templates and the Dump then and modify them to utf8 with notepadd++, upload it to the new system and import the dump into the new system.

Then I should be some kind of all set.


Thanks

Niko
Quote Reply
Re: [el noe] change HTTP Response Header In reply to
Hi,

Yeah, it can be very tricky to get right. If you are using static pages you also need to tell it to write those pages using binmode :utf8. If its dynamic, you need to make sure the header gets the correct type sent (like we discussed in the past posts).

Then you have to convert all the data into utf8 from whatever you are using now (iso-8859-1, western, etc). Obviously, the tables themselves all need tweaking so they are have the correct encoding set on them.

There were a few other bits that I had to do, but I can't remember off the top of my head (I know it took me about 3 days to get it fully right on my own site)

The best way I found to do it, was to clone the site onto a dev server and play with it there. Then either keep notes of all the files / what you have changed, or you could write a little script to "compare" the 2 folders, and see what has changed (thats what I did, as it was easier than trying to remember what I changed :))

You really have to be careful when changing the encoding in them, as I found to my cost (you can end up with double encoding, which is a pig to try and fix)

Hope that helps!

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!