class Shrine::DownloadEndpoint

  1. lib/shrine/plugins/download_endpoint.rb
Superclass: Object

Routes incoming requests. It first asserts that the storage is existent and allowed. Afterwards it proceeds with the file download using streaming.

Methods

Public Class

  1. new

Public Instance

  1. call
  2. inspect

Public Instance Aliases

to_s -> inspect

Public Class methods

new(options)

Writes given options to instance variables.

[show source]
    # File lib/shrine/plugins/download_endpoint.rb
134 def initialize(options)
135   options.each do |name, value|
136     instance_variable_set("@#{name}", value)
137   end
138 end

Public Instance methods

call(env)
[show source]
    # File lib/shrine/plugins/download_endpoint.rb
140 def call(env)
141   request = Rack::Request.new(env)
142 
143   status, headers, body = catch(:halt) do
144     error!(405, "Method Not Allowed") unless request.get?
145 
146     handle_request(request)
147   end
148 
149   headers = Rack::Headers[headers] if Rack.release >= "3"
150   headers["Content-Length"] ||= body.respond_to?(:bytesize) ? body.bytesize.to_s :
151                                                               body.map(&:bytesize).inject(0, :+).to_s
152 
153   [status, headers, body]
154 end
inspect()
[show source]
    # File lib/shrine/plugins/download_endpoint.rb
156 def inspect
157   "#<#{@shrine_class}::DownloadEndpoint>"
158 end