padrino/padrino-framework — pull request #737 by blakedy (2011-12-24 01:09:39+00:00)
Title: Padrino::Cache::Helpers::Page Content-Type Issue

Issue:

Padrino::Cache::Helpers::Page returns Content-Type: text/html on all cached pages.

For example:

```ruby
get '/dummy', :provides => [:json], :cache => true do
{a:1, b:2}.to_json
end
```
The first request will return the appropriate Content-Type: application/json and it'll cache the page. The second request, the cached request, will return the wrong Content-Type: text/html.

Solution:

I'm new to Sinatra and Padrino, but I noticed in Padrino::Cache::Helpers::Page ```halt 200, value```. I know from Sinatra, I can place a hash of headers as the second argument. However, I wanted to figure out how to do it the Padrino way, setting the ```content_type``` prior to the ```halt```. After a few hours, I was unable to figure out how to set the ```content_type``` prior to the ```halt``` and reuse code for finding the appropriate Content-Type based on the ```provides```.
My solution caches the ```content_type``` along with the ```response_buffer```.

Conflicts:

* I maybe breaking the Cache Page paradigm by using it to return JSON and XML. Maybe I should be using Cache Fragments, idk.
* My solution is not bullet proof. The ```cache_key``` should probably be a combination of the Accept header plus the path as maybe a MD5 hash, but that'd break other code.