Sha256: f87117a9eff104578662c0e973d0ff449bcb1f3c837ee5cc35deb4c287c8d79b

Contents?: true

Size: 1.31 KB

Versions: 38

Compression:

Stored size: 1.31 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The default_headers plugin accepts a hash of headers,
    # and overrides the default_headers method in the
    # response class to be a copy of the headers.
    #
    # Note that when using this module, you should not
    # attempt to mutate of the values set in the default
    # headers hash.
    #
    # Example:
    #
    #   plugin :default_headers, 'Content-Type'=>'text/csv'
    #
    # You can modify the default headers later by loading the
    # plugin again:
    #
    #   plugin :default_headers, 'Foo'=>'bar'
    #   plugin :default_headers, 'Bar'=>'baz'
    module DefaultHeaders
      # Merge the given headers into the existing default headers, if any.
      def self.configure(app, headers={})
        app.opts[:default_headers] = (app.default_headers || app::RodaResponse::DEFAULT_HEADERS).merge(headers).freeze
      end 

      module ClassMethods
        # The default response headers to use for the current class.
        def default_headers
          opts[:default_headers]
        end
      end

      module ResponseMethods
        # Get the default headers from the related roda class.
        def default_headers
          roda_class.default_headers
        end
      end
    end

    register_plugin(:default_headers, DefaultHeaders)
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
roda-3.17.0 lib/roda/plugins/default_headers.rb
roda-3.16.0 lib/roda/plugins/default_headers.rb
roda-3.15.0 lib/roda/plugins/default_headers.rb
roda-3.14.1 lib/roda/plugins/default_headers.rb
roda-3.14.0 lib/roda/plugins/default_headers.rb
roda-3.13.0 lib/roda/plugins/default_headers.rb
roda-3.12.0 lib/roda/plugins/default_headers.rb
roda-3.11.0 lib/roda/plugins/default_headers.rb
roda-3.10.0 lib/roda/plugins/default_headers.rb
roda-3.9.0 lib/roda/plugins/default_headers.rb
roda-3.8.0 lib/roda/plugins/default_headers.rb
roda-3.7.0 lib/roda/plugins/default_headers.rb
roda-3.6.0 lib/roda/plugins/default_headers.rb
roda-3.5.0 lib/roda/plugins/default_headers.rb
roda-3.4.0 lib/roda/plugins/default_headers.rb
roda-3.3.0 lib/roda/plugins/default_headers.rb
roda-3.2.0 lib/roda/plugins/default_headers.rb
roda-3.1.0 lib/roda/plugins/default_headers.rb
roda-3.0.0 lib/roda/plugins/default_headers.rb
roda-2.29.0 lib/roda/plugins/default_headers.rb