Skip to content

Commit

Permalink
extracting method into response
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Oct 29, 2010
1 parent 282be8d commit a286c8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 8 additions & 3 deletions lib/restfulie/client/cache/http_ext.rb
Expand Up @@ -59,13 +59,13 @@ def header_value_from(header, expression)

def has_expired_cache?
return true if headers['date'].nil?
max_time = Time.rfc2822(headers['date']) + cache_max_age.seconds
max_time = Time.rfc2822(headers['date'][0]) + cache_max_age.seconds
Time.now > max_time
end

# checks if the header's max-age is available and no no-store if available.
def may_cache?
may_cache_field?(headers['cache-control'])
may_cache_method? && may_cache_field?(headers['cache-control'])
end

# Returns whether this cache control field allows caching
Expand Down Expand Up @@ -113,9 +113,14 @@ def vary_headers_for(request)
end
end

private
def may_cache_method?
verb == :get || verb == :post
end
end

class Restfulie::Client::HTTP::Response
class Net::HTTPResponse
include Restfulie::Client::HTTP::ResponseStatus
include Restfulie::Client::HTTP::ResponseCacheCheck

end
7 changes: 1 addition & 6 deletions lib/restfulie/client/cache/restrictions.rb
Expand Up @@ -4,12 +4,7 @@ class << self

# checks whether this request verb and its cache headers allow caching
def may_cache?(response)
response && may_cache_method?(response.method) && response.may_cache?
end

# only Post and Get requests are cacheable so far
def may_cache_method?(verb)
verb == :get || verb == :post
response && response.may_cache?
end

end
Expand Down

0 comments on commit a286c8e

Please sign in to comment.