You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Da...@ChaosReigns.com on 2009/07/17 19:41:20 UTC

[users@httpd] How do I follow the XHTML Content-Type recommendations?

If a client requests an XHTML file, it says to do normal
content-negotiation.  If the client's HTTP Accept header says they like
text/html more, send them that.  If it says they like application/xhtml+xml
more, send them that.

Fine.  I have even done that successfully with two different files.

Except I can't figure out how to provide multiple Content-Types for a
single file.  And I don't think creating multiple copies of the document
(even with linkes) is an appropriate solution.

   AddType "application/xhtml+xml,text/html; qs=0.01" .html

Tells the client "Content-Type: cation/xhtml+xml,text/html; qs=0.01",
which is no good.

An apache type-map always returns the Content-Type specified by AddType in
my main apache config file.


Test cases:

Both of these files are the same, hard linked to each other.

http://www.chaosreigns.com/xhtmltest/addtype.xhtml

Apache config:

   AddType "application/xhtml+xml,text/html; qs=0.01" .xhtml

The test: 

   $ telnet www.chaosreigns.com 80
   Trying 64.71.152.40...
   Connected to panic.chaosreigns.com.
   Escape character is '^]'.
   HEAD /xhtmltest/addtype.xhtml HTTP/1.1
   Host: www.chaosreigns.com
   Accept: text/html
   
   HTTP/1.1 200 OK
   Date: Fri, 17 Jul 2009 17:28:46 GMT
   Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
   Last-Modified: Fri, 17 Jul 2009 17:15:16 GMT
   ETag: "1c93d4-1aa-46ee9ee94b100"
   Accept-Ranges: bytes
   Content-Length: 426
   Content-Type: application/xhtml+xml,text/html; qs=0.01


http://www.chaosreigns.com/xhtmltest/typemap.var

File contents:

  URI: typemap

  URI: typemap.html
  Content-Type: text/html; qs=0.01
  
  URI: typemap.html
  Content-Type: application/xhtml+xml; qs=1

The test:

   telnet www.chaosreigns.com 80
   Trying 64.71.152.40...
   Connected to panic.chaosreigns.com.
   Escape character is '^]'.
   HEAD /xhtmltest/typemap.var HTTP/1.1
   Host: www.chaosreigns.com
   Accept: application/xhtml+xml
   
   HTTP/1.1 200 OK
   Date: Fri, 17 Jul 2009 17:35:13 GMT
   Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
   Content-Location: typemap.html
   Vary: negotiate,accept
   TCN: choice
   Last-Modified: Fri, 17 Jul 2009 17:15:16 GMT
   ETag: "1c93d4-1aa-46ee9ee94b100;1c93d3-7e-46eea269bf400"
   Accept-Ranges: bytes
   Content-Length: 426
   Content-Type: text/html

When I have "AddType "application/xhtml+xml" .html" in my main apache
config and specify Content-Type: text/html, I get application/xhtml+xml.
This is its current state.

I think I should file bugs for these?



It also suggests that if neither text/html or application/xhtml+xml are
listed in the Accept header, that application/xhtml+html should not be
used.  I suppose it would be nice to be able to do that for particularly
bad browsers.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] SOLVED Re: [users@httpd] How do I follow the XHTML Content-Type recommendations?

Posted by André Warnier <aw...@ice-sa.com>.
Darxus@ChaosReigns.com wrote:
> If a browser with a User-Agent containing "MSIE" 
there seems to be a contradiction in terms here..
;-)

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] SOLVED Re: [users@httpd] How do I follow the XHTML Content-Type recommendations?

Posted by Da...@ChaosReigns.com.
If a browser with a User-Agent containing "MSIE" requests a .html file,
change its Content-Type to "text/html" (because application/xhtml+xml works
in all other browsers):

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RewriteCond %{REQUEST_URI} \.html$
RewriteRule .* - [T=text/html]

 - http://www.ibm.com/developerworks/xml/library/x-tipapachexhtml/index.html

Use Content-Type application/xml and XSLT to get IE to convert XHTML to
HTML and parse it:  http://www.w3.org/MarkUp/2004/xhtml-faq#ie

-- 
"I would believe only in a God that knows how to Dance." - Nietzsche
http://www.ChaosReigns.com                                 Guns save lives.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How do I follow the XHTML Content-Type recommendations?

Posted by Da...@ChaosReigns.com.
I moved this bit to the top because I think it makes everything else
irrelevant:

> Note however that old browsers who do not understand the type  
> "application/xhtml+xml", are *really* old.
>
> Note also that no matter what the server sends as Content-Type header,  
> if the browser is IE, it will ignore it anyway and make its own guess.

No.

If these statements were true, I would not have started this conversation.

Every version of IE, when provided with any file, with "Content-Type:
application/xhtml+xml", will make no attempt to display the page, and will
ask the user if they would like to save it to a file.

If you provide XHTML 1.0 to a recent version of IE with "Content-Type:
text/html", it will render the page.  (http://www.microsoft.com/ is valid
XHTML 1.0 Transitional.)

I apologize for not starting this conversation with this practical
example.


On 07/18, Andr? Warnier wrote:
> Yes, because it would be very confusing otherwise.

I disagree.

> But it is not what I think that counts; what counts is the HTTP RFC.

  5.  Content-Type Header Field

     The purpose of the Content-Type field is to describe the data
     contained in the body fully enough that the receiving user agent can
     pick an appropriate agent or mechanism to present the data to the
     user, or otherwise deal with the data in an appropriate manner.

- RFC2045 - Multipurpose Internet Mail Extensions (MIME) Part One

To "...describe the data..." contained in the an xhtml file "...fully
enough that..." IE "...can pick an appropriate mechanism to present
the data to the user, or otherwise deal with the data in an appropriate
manner", the Content-Type header must be "text/html".

>> Did you read the part about why XHTML should be served to some clients as
>> text/html, and others as application/xhtml+xml?
> Wherever that is, I disagree with it.  Content should be served with a  

I apologize for this as well, I thought I
provided the url at the beginning of my first email:
http://www.w3.org/TR/xhtml-media-types/#media-types 
- XHTML Media Types - Second Edition: Serving the Most Appropriate
Content to Multiple User Agents from a Single Document Source

Disagreeing with the W3C, author of all HTML standards which the Apache
HTTPD was primarily designed to provide, on specifically what Content-Types
this sort of software should use for documents it has written the standards
for... seems... not useful.

>> But XHTML 1.0 was created to be compatible
>> with existing browsers that didn't understand XML, so they should be served
>> the same file, with the different Content-Type of text/html.
> That may be where we disagree.  They could be sent the same content, but  
> not necessarily the same file.

What?  You feel a reason to duplicate the content why?

> No, and that is where you are confused. You are confusing resource and file.
> Quote from http://httpd.apache.org/docs/2.2/content-negotiation.html:

I know the difference between a resource and a file.  It's a pretty neat
distinction.  I first used it with a type-map file to serve svg to capable
browsers, and a png converted from the svg to others.

> A resource is a conceptual entity identified by a URI (RFC 2396). An  
> HTTP server like Apache provides access to representations of the  
> resource(s) within its namespace, with each representation in the form  
> of a sequence of bytes with *a defined media type*, character set,  

application/xhtml+xml is defined.  Right here:
http://www.rfc-editor.org/rfc/rfc3236.txt

>From a list provided by IANA, as specified by the MIME RFCs even:
http://www.iana.org/assignments/media-types/

>>>> Except I can't figure out how to provide multiple Content-Types for a
>>>> single file.
>>> Logical, because you can't.  One document/file has only one MIME 
>>> type,  not several.
>> Why not?
> That, you should ask the people who have created all these Internet  
> RFC's.  I am sure that they have thought long and hard about it.

I addressed this above by quoting RFC2045.

> The server cannot answer : here is a Bourgogne or Bordeaux; quality =  
> 0.9.  That just does not make sense, even if the Bordeaux is a Chateau  
> Cheval Blanc 1er Grand Cru Class? St Emilion.

I have never suggested or expressed interested in using a Content-Type
header with multiple types.  That would obviously be useless.

> But Apache should not send 2 MIME types in a Content-type header,  
> because that is illegal according to the HTTP specification, and Apache,  
> being a HTTP server, has to respect the HTTP specification.

Agreed.

> It /may/ work with a single file, and another symbolic link to it, but  
> of that I am not sure.

I am surprised to find that it does not work with hard links.  Even with
"FileETag None".

> (Personally, I think that you /should/ have 2 files, because their  
> content should not be identical.  If they are proper html and xhtml,  
> then at least their DOCTYPE and <meta http-equiv="content-type"> tags  
> should be different)

Perhaps it would be useful to say that xhtml is html, which makes it valid
to call it text/html.  It just also confirms to xml.  Not very relevant
though.  There is no practical reason to have two different files in
two different formats.

> Note however that old browsers who do not understand the type  
> "application/xhtml+xml", may also not send an "Accept" header.

Indeed.  This was the reason the W3C recommended sending text/html to
browsers which do not list it or application/xhtml+xml in an Accept header.
I am far less concerned with this.

> Note also that if you do not like how Apache does it, you can write your  
> own add-on modules to do it any way you like.
> That's what filters are for.
> You could probably even achieve what you want more precisely by using  
> the mod_SetEnvIf, mod_headers and/or mod_rewrite.

These sort of possibilities have occurred to me.  Thank you for pointing me
in more specific directions.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How do I follow the XHTML Content-Type recommendations?

Posted by André Warnier <aw...@ice-sa.com>.
Darxus@ChaosReigns.com wrote:
> So it's not possible to serve one file with two different Content-Types,
> and you think that is as it should be?

Yes, because it would be very confusing otherwise.
But it is not what I think that counts; what counts is the HTTP RFC.

> 
> Did you read the part about why XHTML should be served to some clients as
> text/html, and others as application/xhtml+xml?
Wherever that is, I disagree with it.  Content should be served with a 
Content-Type that corresponds to what the content /is/, not to what the 
client understands.

> 
> application/xhtml+xml is the correct Content-Type for xhtml.  So it should
> be sent with that Content-Type.
Yes, and yes.

   But XHTML 1.0 was created to be compatible
> with existing browsers that didn't understand XML, so they should be served
> the same file, with the different Content-Type of text/html.
That may be where we disagree.  They could be sent the same content, but 
not necessarily the same file.

> 
> 
> On 07/17, Andr? Warnier wrote:
>> No, if a client asks for the URL "/abc/file.html", it wants the resource  
>> corresponding to that URL.
> 
> Right.  And in this case, regardless of which Content-Type the client
> wants that resource in, it's the same file.  

No, and that is where you are confused. You are confusing resource and file.
Quote from http://httpd.apache.org/docs/2.2/content-negotiation.html:

A resource is a conceptual entity identified by a URI (RFC 2396). An 
HTTP server like Apache provides access to representations of the 
resource(s) within its namespace, with each representation in the form 
of a sequence of bytes with *a defined media type*, character set, 
encoding, etc. Each resource may be associated with zero, one, or more 
than one representation at any given time. If multiple representations 
are available, the resource is referred to as negotiable and each of its 
representations is termed a variant. The ways in which the variants for 
a negotiable resource vary are called the dimensions of negotiation.

Unquote

> 
>>> Except I can't figure out how to provide multiple Content-Types for a
>>> single file.
>> Logical, because you can't.  One document/file has only one MIME type,  
>> not several.
> 
> Why not?
That, you should ask the people who have created all these Internet 
RFC's.  I am sure that they have thought long and hard about it.

> 
>> Unless you mean what is described here :
>> http://httpd.apache.org/docs/2.2/content-negotiation.html
>> (Read it, don't just guess how it works)
> 
> I read it before posting.
> 
>>>    AddType "application/xhtml+xml,text/html; qs=0.01" .html
>> What makes you think that you can do that ?
> 
> I tried it because it should work, not because I believed documentation
> said it would.
> 
>>> Tells the client "Content-Type: application/xhtml+xml,text/html; qs=0.01",
>>> which is no good.
>> No, and it's even invalid.
> 
> That's what I meant by "which is no good".

No, you are confused again.

The client says :
"I want a glass of red wine.  If you happen to have a Bourgogne and/or a 
Bordeaux, then I prefer the Bourgogne (0.9), followed by the Bordeaux 
(0.5).  And otherwise, any red wine will do (0.1)."

The server looks at which variants it has in the cellar.  It finds a red 
Bordeaux, and a red Spanish table wine. It decides that the Bordeaux 
best matches what the client wants.  So it sends the Bordeaux, and adds 
a header saying  : "here is a red Bordeaux".

The server cannot answer : here is a Bourgogne or Bordeaux; quality = 
0.9.  That just does not make sense, even if the Bordeaux is a Chateau 
Cheval Blanc 1er Grand Cru Classé St Emilion.

> 
>> I believe you are a bit confused.
>> Your typemap file has the same mistake.
> 
> If what you said above is correct, I am not confused.  I want to do
> something Apache is currently incapable of.
It is phrases like that, which make these posts endearing.

You can get the correct response from Apache, but you have to do it 
right, according to how it works, which is explained in the 
documentation.  And not according to how you think it /should/ work.

> Lack of support for this capability is lack of support for XHTML.  
Not really.  The one that should support XHTML is the client, not the 
server.
Apache doesn't know anything about HTML or XHTML or XML or whatever 
content type, and does not need to know.  It serves content, whatever 
that content is; it does not look inside of it.  It is only supposed to 
indicate to the client the MIME type of this content, which it 
determines according to a set of configuration rules, which you are 
creating.

So, if you tell Apache that a file whose name ends in ".xyz" has a 
content-type of "image/bubblegum", then that is what Apache will put in 
the Content-type it sends to the client.

But Apache should not send 2 MIME types in a Content-type header, 
because that is illegal according to the HTTP specification, and Apache, 
being a HTTP server, has to respect the HTTP specification.

You can do an
AddType text/html .html
  and an
AddType application/xhtml+xml .xhtml
but you cannot combine them into one single AddType.
(and you should check first if these types are not already in Apache by 
default; they probably are)

Let's go back to the type-map file and the explanation about content 
negociation, and think again. (Maybe also look at MultiViews).

To use the standard Apache content-negociation,
you have to create 2 files, and then use your type-map to return one 
/or/ the other, with the corresponding Content-type.
It /may/ work with a single file, and another symbolic link to it, but 
of that I am not sure.

(Personally, I think that you /should/ have 2 files, because their 
content should not be identical.  If they are proper html and xhtml, 
then at least their DOCTYPE and <meta http-equiv="content-type"> tags 
should be different)

Note however that old browsers who do not understand the type 
"application/xhtml+xml", may also not send an "Accept" header.

Note however that old browsers who do not understand the type 
"application/xhtml+xml", are *really* old.

Note also that no matter what the server sends as Content-Type header, 
if the browser is IE, it will ignore it anyway and make its own guess.

Note also that if you do not like how Apache does it, you can write your 
own add-on modules to do it any way you like.
That's what filters are for.
You could probably even achieve what you want more precisely by using 
the mod_SetEnvIf, mod_headers and/or mod_rewrite.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How do I follow the XHTML Content-Type recommendations?

Posted by Da...@ChaosReigns.com.
So it's not possible to serve one file with two different Content-Types,
and you think that is as it should be?

Did you read the part about why XHTML should be served to some clients as
text/html, and others as application/xhtml+xml?

application/xhtml+xml is the correct Content-Type for xhtml.  So it should
be sent with that Content-Type.  But XHTML 1.0 was created to be compatible
with existing browsers that didn't understand XML, so they should be served
the same file, with the different Content-Type of text/html.


On 07/17, Andr? Warnier wrote:
> No, if a client asks for the URL "/abc/file.html", it wants the resource  
> corresponding to that URL.

Right.  And in this case, regardless of which Content-Type the client
wants that resource in, it's the same file.  

>> Except I can't figure out how to provide multiple Content-Types for a
>> single file.
>
> Logical, because you can't.  One document/file has only one MIME type,  
> not several.

Why not?

> Unless you mean what is described here :
> http://httpd.apache.org/docs/2.2/content-negotiation.html
> (Read it, don't just guess how it works)

I read it before posting.

>>    AddType "application/xhtml+xml,text/html; qs=0.01" .html
>
> What makes you think that you can do that ?

I tried it because it should work, not because I believed documentation
said it would.

>> Tells the client "Content-Type: application/xhtml+xml,text/html; qs=0.01",
>> which is no good.
>
> No, and it's even invalid.

That's what I meant by "which is no good".

> I believe you are a bit confused.
> Your typemap file has the same mistake.

If what you said above is correct, I am not confused.  I want to do
something Apache is currently incapable of.

Lack of support for this capability is lack of support for XHTML.  

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How do I follow the XHTML Content-Type recommendations?

Posted by André Warnier <aw...@ice-sa.com>.
Darxus@ChaosReigns.com wrote:
> If a client requests an XHTML file, it says to do normal
> content-negotiation.

No, if a client asks for the URL "/abc/file.html", it wants the resource 
corresponding to that URL.

   If the client's HTTP Accept header says they like
> text/html more, send them that.
/This/ is where content negociation starts, /if/ the server happens to 
have more that one representation of the requested resource available.
The client indicates a /preference/ for one or the other representation 
of the resource, /in case/ the server has several.

   If it says they like application/xhtml+xml
> more, ... (and if we have it) ... send them that.

kind of, but it's either, or.

> 
> Fine.  I have even done that successfully with two different files.
> 
> Except I can't figure out how to provide multiple Content-Types for a
> single file.

Logical, because you can't.  One document/file has only one MIME type, 
not several.

Unless you mean what is described here :
http://httpd.apache.org/docs/2.2/content-negotiation.html
(Read it, don't just guess how it works)

The server /tries/ to find the alternative file which matches the client 
preferences best.  Once it finds it, it will send /that/ file, with the 
MIME type of /that/ file in the Content-type header.

   And I don't think creating multiple copies of the document
> (even with linkes) is an appropriate solution.
> 
>    AddType "application/xhtml+xml,text/html; qs=0.01" .html

What makes you think that you can do that ?
Not this :
http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype
The first argument to the AddType directive is /one/ MIME media type, 
not several, and no parameters.  The following argument(s) is a list of 
possible extensions.

> 
> Tells the client "Content-Type: cation/xhtml+xml,text/html; qs=0.01",
> which is no good.

No, and it's even invalid.
See http://www.faqs.org/rfcs/rfc2616.html, 3.7 & 14.17

Content-type: text/html; charset=UTF-8
is a valid header, the above is not.

> 
> An apache type-map always returns the Content-Type specified by AddType in
> my main apache config file.
Re-read
http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addtype

I believe you are a bit confused.
Your typemap file has the same mistake.

Because of that, your later tests do not make much sense.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org