Class: Webspicy::Web::Specification::Post::LastModifiedCachingProtocol
- Inherits:
-
Object
- Object
- Webspicy::Web::Specification::Post::LastModifiedCachingProtocol
- Includes:
- Specification::Post
- Defined in:
- lib/webspicy/web/specification/post/last_modified_caching_protocol.rb
Constant Summary collapse
- MATCH =
/It supports the Last-Modified\/If-Modified-Since caching protocol/
Constants included from Specification::Condition
Specification::Condition::MATCH_ALL
Instance Attribute Summary
Attributes included from Specification::Condition
#matching_description, #tester
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Specification::Post
#contribute_to_openapi_verb, #instrument
Methods included from Specification::Condition
#bind, #fail!, #sooner_or_later, #to_s
Class Method Details
.match(service, descr) ⇒ Object
10 11 12 13 |
# File 'lib/webspicy/web/specification/post/last_modified_caching_protocol.rb', line 10 def self.match(service, descr) return nil unless descr =~ MATCH LastModifiedCachingProtocol.new end |
Instance Method Details
#check! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/webspicy/web/specification/post/last_modified_caching_protocol.rb', line 15 def check! res = invocation.response last_modified = res.headers['Last-Modified'] fail!("No last-modified response header found") unless last_modified # check it fits the HTTP-date format or fail Time.httpdate(last_modified) rescue fail!("Not valid Last-Modified response header") url, _ = test_case.specification.instantiate_url(test_case.params) url = scope.to_real_url(url, test_case){|u,_| u } response = client.api.get(url, {}, test_case.headers.merge({ 'If-Modified-Since' => last_modified })) fail!("304 expected") unless response.status == 304 response = client.api.get(url, {}, test_case.headers.merge({ 'If-Modified-Since' => "Thu, 08 Jun 1970 19:06:27 GMT" })) fail!("2xx expected") if response.status == 304 end |