views:

22

answers:

1

So I was wondering what should be done with HTTP Content Negotiation regarding requests where the returned data may have multiple valid MIME types.

For example if say I have some arbitrary data that has the following possible MIME types:

text/data,application/x-data,application/data+xml

Given that there are multiple MIME types possible a client application requesting data of this form from my web application should reasonably expect to receive that kind of data regardless of which of the MIME types they use in their requests Accept header. BUT there will generally be some consensus about which type is the canonical type for this data (ie. one will be a proper registered MIME type with the IETF while the others will be pre-registration or pre-standardisation types).

So my question is should I in replying to these requests set my returned Content-Type header to be the canonical type or the requested type? Which is better practice?

Should I always return the canonical type or should I echo back the requested type to ensure compatibility with older/poorly written apps that haven't been updated? Currently I'm returning the canonical type as this seems to be to be a better approach and what most people are doing with the data types I'm working with.

This is somewhat subjective so if you think it should be community wiki instead of a question let me know and I'll consider changing it

A: 

When a user-agent (client application) requests a resource they will beacon out several different mime-types for that single requested resource. This occurs for compatibility reasons to let the web server know what the user-agent is capable of accepting. It is the job of the server to determine what the mime-type of the resource will actually be.

It doesn't hurt to make some decisions on the server side to in finding the appropriate response. If you wish to serve all HTML pages as XML, for instance, but a major user-agent does not support the necessary mime-type you can supply a dynamic response using an assisting technology, such as PHP or ASP. In the case of this example the best idea would be to set the correct mime-type as the canonical and if the user-agent does not support the canonical then serve them something else that they will support, otherwise everybody gets the canonical.

In my case the MIME types are all valid types for the same data format (the data returned will be identical regardless of the type) so it's not an issue of generating an appropriate response but of which MIME type should I return in the Content-Type header
RobV
In that case then pick the one you believe to be most widely supported and is most appropriate.