our $variants = [
[qw| xhtml 1.000 application/xhtml+xml |],
- [qw| html 0.001 text/html |],
+ [qw| html 0.900 text/html |],
];
sub process {
my $self = shift;
my ($c) = @_;
my $return = $self->next::method(@_);
-
if ($c->request->header('Accept') && $c->response->headers->{'content-type'} =~ m|text/html|) {
+ $self->pragmatic_accept($c);
my $var = choose($variants, $c->request->headers);
if ($var eq 'xhtml') {
$c->response->headers->{'content-type'} =~ s|text/html|application/xhtml+xml|;
return $return;
}
+sub pragmatic_accept {
+ my ($self, $c) = @_;
+ my $accept = $c->request->header('Accept');
+ if ($accept =~ m|text/html|) {
+ $accept =~ s!\*/\*\s*([,]+|$)!*/*;q=0.5$1!;
+ } else {
+ $accept =~ s!\*/\*\s*([,]+|$)!text/html,*/*;q=0.5$1!;
+ }
+ $c->request->header('Accept' => $accept);
+}
+
1;
__END__
use strict;
use warnings;
use base qw/Catalyst::View::TT::XHTML MyApp::View::TT/;
-
+
1;
-
+
=head1 DESCRIPTION
This is a very simple sub-class of L<Catalyst::View::TT>, which sets
to process that MIME type.
Changing the C<Content-Type> causes browsers to interpret the page as
-strict XHTML, meaning that the markup must be well formed.
+XML, meaning that the markup must be well formed.
This is useful when you're developing your application, as you know that
-all pages you view are rendered strictly, so any markup errors will show
-up at once.
+all pages you view are parsed as XML, so any errors caused by your markup
+not being well-formed will show up at once.
=head1 METHODS
to render the template, and then changing the response C<Content-Type> if
appropriate (from the requests C<Accept> header).
+=head2 pragmatic_accept
+
+Some browsers (such as Internet Explorer) have a nasty way of sending
+Accept */* and this claiming to support XHTML just as well as HTML.
+Saving to a file on disk or opening with another application does
+count as accepting, but it really should have a lower q value then
+text/html. This sub takes a pragmatic approach and corrects this mistake
+by modifying the Accept header before passing it to content negotiation.
+
=head1 BUGS
There should be a more elegant way to inherit the config of your normal
=over
-=item David Dorward - test patches
+=item David Dorward - test patches and */* pragmatism.
=back