Class: Rack::QiniuMock::Context
- Inherits:
-
Object
- Object
- Rack::QiniuMock::Context
- Defined in:
- lib/rack/qiniu_mock/context.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) {|_self| ... } ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(app, opts = {}) {|_self| ... } ⇒ Context
Returns a new instance of Context.
6 7 8 9 10 11 12 13 |
# File 'lib/rack/qiniu_mock/context.rb', line 6 def initialize(app, opts={}) @app = app @root = File.("public", Rails.root) @config = YAML.load_file(File.("config/qiniu_mock.yml", Rails.root)) @separator = @config['separator'] || '-' @suffixs = @config['suffixs'] || {} yield self if block_given? end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/qiniu_mock/context.rb', line 15 def call(env) original_file, mtime = get_original_file(::Rack::Utils.unescape(env['PATH_INFO'])) if original_file data = original_file.to_blob [200, { "Content-Type" => original_file.mime_type, "Content-Length" => data.size.to_s, "Cache-Control" => "public, max-age=31536000", "Last-Modified" => mtime.httpdate }, [data]] else @app.call(env) end end |