lib/dragonfly/response.rb in dragonfly-0.8.1 vs lib/dragonfly/response.rb in dragonfly-0.8.2

- old
+ new

@@ -14,15 +14,17 @@ @job, @env = job, env @app = @job.app end def to_response - if etag_matches? - # Not Modified + if !(request.head? || request.get?) + [405, method_not_allowed_headers, ["#{request.request_method} method not allowed"]] + elsif etag_matches? [304, cache_headers, []] - else - # Success + elsif request.head? + [200, success_headers.merge(cache_headers), []] + elsif request.get? [200, success_headers.merge(cache_headers), job.result] end rescue DataStorage::DataNotFound => e [404, {"Content-Type" => 'text/plain'}, [e.message]] end @@ -62,9 +64,16 @@ def content_disposition_header parts = [] parts << content_disposition if content_disposition parts << %(filename="#{URI.encode(filename)}") if filename parts.any? ? {"Content-Disposition" => parts.join('; ')} : {} + end + + def method_not_allowed_headers + { + 'Content-Type' => 'text/plain', + 'Allow' => 'GET, HEAD' + } end def content_disposition @content_disposition ||= evaluate(app.content_disposition) end