Sha256: 0daa918d79c13887a02dacf00be49b9001725eeca0e52480f3d15cb180c67c5d

Contents?: true

Size: 852 Bytes

Versions: 1

Compression:

Stored size: 852 Bytes

Contents

class Roda
  module RodaPlugins
    # The delete_nil_headers plugin deletes any headers whose
    # value is set to nil.  Because of how default headers are
    # set in Roda, if you have a default header but don't want
    # to set it for a specific request, you need to use this plugin
    # and set the value to nil so that 
    #
    # The following example will return "<foo>" as the body.
    #
    #   plugin :h
    #
    #   route do |r|
    #     h('<foo>')
    #   end
    module DeleteHeaders
      module ResponseMethods
        def finish
          res = super
          res[1].delete_if{|_, v| v.nil?}
          res
        end

        def finish_with_body(_)
          res = super
          res[1].delete_if{|_, v| v.nil?}
          res
        end
      end
    end

    register_plugin(:delete_headers, DeleteHeaders)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roda-1.3.0 lib/roda/plugins/delete_nil_headers.rb