Sha256: 10f19f9ce71e04fc20281c9538d8becfc1bd4807f98bdae5fb29f8c61555ec6b

Contents?: true

Size: 704 Bytes

Versions: 18

Compression:

Stored size: 704 Bytes

Contents

# Patch Sinatra::Response#finish to not calculate Content-Length unless
# all members of an array are strings
class Sinatra::Response
  def finish
    if status.to_i / 100 == 1
      headers.delete "Content-Length"
      headers.delete "Content-Type"
    elsif RDF::Query::Solutions === body
      # Don't calculate content-length here
    elsif Array === body and not [204, 304].include?(status.to_i)
      headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
    end

    # Rack::Response#finish sometimes returns self as response body. We don't want that.
    status, headers, result = super
    result = body if result == self
    [status, headers, result]
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sparql-1.1.1 lib/sinatra/sparql/extensions.rb
sparql-1.1.0 lib/sinatra/sparql/extensions.rb
sparql-1.1.0p0 lib/sinatra/sparql/extensions.rb
sparql-1.0.8 lib/sinatra/sparql/extensions.rb
sparql-1.0.7 lib/sinatra/sparql/extensions.rb
sparql-1.0.6 lib/sinatra/sparql/extensions.rb
sparql-1.0.5 lib/sinatra/sparql/extensions.rb
sparql-1.0.4 lib/sinatra/sparql/extensions.rb
sparql-1.0.3 lib/sinatra/sparql/extensions.rb
sparql-1.0.2 lib/sinatra/sparql/extensions.rb
sparql-1.0.1 lib/sinatra/sparql/extensions.rb
sparql-1.0.0 lib/sinatra/sparql/extensions.rb
sparql-0.3.3 lib/sinatra/sparql/extensions.rb
sparql-0.3.2 lib/sinatra/sparql/extensions.rb
sparql-0.3.1 lib/sinatra/sparql/extensions.rb
sparql-0.3.0 lib/sinatra/sparql/extensions.rb
sparql-0.1.1 lib/sinatra/sparql/extensions.rb
sparql-0.1.0 lib/sinatra/sparql/extensions.rb