[XHR] No way to tell a request originates from an XHR object

Hi,

Within the Mobile Web Best Practices Working Group, the Content 
Transformation Task Force is writing guidelines [1] for content 
transformation proxies and content providers to be able to communicate 
their intentions regarding a given HTTP message.

It occurred to us that from a proxy's point of view (note it also 
applies from a server's point of view, but that's not the point here), 
there is no way to tell whether a given HTTP request originates from the 
browser itself or from an XHR object.

In the context of content transformation that is a problem because such 
HTTP messages should be passed untouched by the content transformation 
proxies: an XHR call involves that some client code will be run on 
receipt of the response, so any transformation is likely to break the 
content delivered by the device.

We initially thought that using dedicated "data" content-types (such as 
application/json) would solve the problem, but then it's typically 
common and valid to fetch an XHTML page using an XHR object for display 
purposes.

Still from a content transformation's point of view, we've solved the 
problem by recommending that content providers include a "Cache-Control: 
no-transform" directive in the HTTP headers of XHR calls to "switch off" 
the proxy when they don't want the message to be transformed in any way. 
This still means that content providers have to update their content for 
this to work, but that's another story.

We were wondering if that use case would not meet other similar use 
cases in other areas that would require an easy way to tell that a 
request originates from an XHR object. Possible solutions:
 1. amending the User-Agent string to include an "XHR"-like string somewhere
 2. defining an additional header such as "X-Ajax-Engine" [2]
 ... and hopefully better solutions we haven't thought about.

Is there a reason for not willing to distinguish between a browser 
request and an XHR call from within the browser?
Did we get something wrong and is it already possible to know a request 
originates from an XHR object?
Is it something that you think could be worth considering?

On behalf of the Content Transformation Task Force,
François Daoust, BPWG Staff Contact.

[1] http://www.w3.org/TR/ct-guidelines
[2] 
http://www.dev411.com/blog/2006/06/30/should-there-be-a-xmlhttprequest-user-agent

Received on Wednesday, 7 May 2008 10:39:01 UTC