13

I'm serving a set of resources through content negotiation. Concretely, any URL can be represented in different formats, depending on the client's Accept header.

An example of this can be seen at Facebook:

  • curl -H "Accept: application/json" http://graph.facebook.com/daft-punk
    results in JSON
  • curl -H "Accept: text/turtle" http://graph.facebook.com/daft-punk
    results in Turtle

I'm looking for a CDN that caches content based on URL and the client's Accept header.

Example of what goes wrong

CloudFlare doesn't support this: if one client asks for HTML, then all subsequent requests to that URL receive the HTML representation, regardless of their preferences. Others have similar issues.

For example, if I would place CloudFlare over graph.facebook.com(and configure it to cache “extensionless” resources, which it does not by default), then it would behave incorrectly:

  1. I ask for http://graph.facebook.com/daft-punk in JSON through curl;
    in response, CloudFlare asks the JSON original from the server, caches it, and serves it.
  2. I ask for http://graph.facebook.com/daft-punk through my browser (thus in HTML);
    in response CloudFlare sends the cached JSON (!) representation, even though the original server would have sent the HTML version.

What would be needed instead

The correct behavior would be that CloudFlare asks the server again, since the second client had a different Accept header. After this, requests with similar Accept headers can be served from cache.

Which CDN solutions support content-negotiation, and also cache negotiated content?
So note that only respecting Accept is not enough; negotiated responses should be cached too.



PS1: It's easy to make your own caching servers support it. For instance, for nginx:

proxy_cache_key "$scheme$host$request_uri$http_accept";

Note how the client's Accept header is part of the key that indexes the cache. I want that on CDN.


PS2: It is not an option to use different URLs for different representations. My application is in the Linked Data domain, where URLs play an important role for identification.

4

2 回答 2

0

似乎 maxcdn 仍然可以为内容协商设置自定义 nginx 规则(尽管他们的常见问题解答说) - http://blog.maxcdn.com/how-to-reduce-image-size-with-webp-automagically/#comment-1048561182

于 2013-12-18T19:09:26.917 回答
-2

我想不出任何方式我们会在这个时候影响这一切。例如,我们默认不缓存 HTML。你真的见过这个问题吗?你开过支持票吗?

于 2013-12-02T19:41:41.487 回答