Sha256: 51f349c5fad9c8c7d8f74cdc3f270c2b92c4ad7657be6be0114f01ace93604cd

Contents?: true

Size: 819 Bytes

Versions: 25

Compression:

Stored size: 819 Bytes

Contents

module Merb
  module Rack

    class ConditionalGet < Merb::Rack::Middleware

      # :api: plugin
      def call(env)
        status, headers, body = @app.call(env)

        if document_not_modified?(env, headers)
          status = 304
          body = Merb::Const::EMPTY_STRING
          # set Date header using RFC1123 date format as specified by HTTP
          # RFC2616 section 3.3.1.
        end
        
        [status, headers, body]
      end
    
    private
      # :api: private
      def document_not_modified?(env, headers)
        if etag = headers[Merb::Const::ETAG]
          etag == env[Merb::Const::HTTP_IF_NONE_MATCH]
        elsif last_modified = headers[Merb::Const::LAST_MODIFIED]
          last_modified == env[Merb::Const::HTTP_IF_MODIFIED_SINCE]
        end
      end
    end
    
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
merb-core-1.0.7.1 lib/merb-core/rack/middleware/conditional_get.rb
merb-core-1.0.7 lib/merb-core/rack/middleware/conditional_get.rb
merb-core-1.0.9 lib/merb-core/rack/middleware/conditional_get.rb
merb-core-1.0.8 lib/merb-core/rack/middleware/conditional_get.rb
merb-core-1.0 lib/merb-core/rack/middleware/conditional_get.rb