Sha256: 78034afe714f408270575ea3265a75358246ea713a20ccdfa92139d31b919abb

Contents?: true

Size: 1.03 KB

Versions: 29

Compression:

Stored size: 1.03 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The delete_empty_headers plugin deletes any headers whose
    # value is set to the empty string.  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 header value to the empty string, and Roda will automatically
    # delete the header.
    module DeleteEmptyHeaders
      module ResponseMethods
        # Delete any empty headers when calling finish
        def finish
          delete_empty_headers(super)
        end

        # Delete any empty headers when calling finish_with_body
        def finish_with_body(_)
          delete_empty_headers(super)
        end

        private

        # Delete any empty headers from response
        def delete_empty_headers(res)
          res[1].delete_if{|_, v| v.is_a?(String) && v.empty?}
          res
        end
      end
    end

    register_plugin(:delete_empty_headers, DeleteEmptyHeaders)
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
roda-3.88.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.87.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.86.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.85.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.84.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.83.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.82.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.81.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.79.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.78.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.77.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.76.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.75.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.74.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.73.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.72.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.71.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.70.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.69.0 lib/roda/plugins/delete_empty_headers.rb
roda-3.68.0 lib/roda/plugins/delete_empty_headers.rb