Sha256: f73481589776450bf054ef52375cc27ff80677515d3ae3e22a6e83016ce007bd

Contents?: true

Size: 1.34 KB

Versions: 16

Compression:

Stored size: 1.34 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The drop_body plugin automatically drops the body and
    # Content-Type/Content-Length headers from the response if
    # the response status indicates that the response should
    # not include a body (response statuses 100, 101, 102, 204,
    # and 304).  For response status 205, the body and Content-Type
    # headers are dropped, but the Content-length header is set to
    # '0' instead of being dropped.
    module DropBody
      module ResponseMethods
        DROP_BODY_STATUSES = [100, 101, 102, 204, 205, 304].freeze
        RodaPlugins.deprecate_constant(self, :DROP_BODY_STATUSES)

        DROP_BODY_RANGE = 100..199
        private_constant :DROP_BODY_RANGE

        # If the response status indicates a body should not be
        # returned, use an empty body and remove the Content-Length
        # and Content-Type headers.
        def finish
          r = super
          case r[0]
          when DROP_BODY_RANGE, 204, 304
            r[2] = EMPTY_ARRAY
            h = r[1]
            h.delete(RodaResponseHeaders::CONTENT_LENGTH)
            h.delete(RodaResponseHeaders::CONTENT_TYPE)
          when 205
            r[2] = EMPTY_ARRAY
            empty_205_headers(r[1])
          end
          r
        end
      end
    end

    register_plugin(:drop_body, DropBody)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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