Sha256: 07df0fe9bec7b8b48be9ad5ce77778aa454c0b8044a9dfe79862dacbef23cda2

Contents?: true

Size: 995 Bytes

Versions: 6

Compression:

Stored size: 995 Bytes

Contents

# -*- encoding: binary -*-

# matches GET and HEAD requests in the format of "/:namespace/:dkey"
# where +:dkey+ may contain multiple slashes
#
# If a client were to make a request to "http://example.com/d/foo/bar",
# this endpoint would respond with the file from the "d" domain
# with the key "foo/bar".
#
# To use as middleware:
#    require 'regurgitator'
#    db = Sequel.connect('mysql2://user@example.com/mogilefs')
#    use Regurgitator::DomainPath, db
#
# See the {domain_path.ru}[link:examples/domain_host.ru]
# example for a standalone app.
class Regurgitator::DomainPath
  include Regurgitator::Endpoint

  def call(env) # :nodoc:
    case env['REQUEST_METHOD']
    when 'GET', 'HEAD'
      env['PATH_INFO'] =~ %r{\A/([^/]+)/(.+)\z} or return @app.call(env)
      serve_file(env, $1, $2)
    else
      @app.call(env)
    end
  end

  def initialize(app, opts) # :nodoc:
    opts = { :db => opts } unless Hash === opts
    endpoint_init(app, opts[:db], opts[:reproxy_key])
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
regurgitator-0.7.0 lib/regurgitator/domain_path.rb
regurgitator-0.6.0 lib/regurgitator/domain_path.rb
regurgitator-0.5.0 lib/regurgitator/domain_path.rb
regurgitator-0.4.0 lib/regurgitator/domain_path.rb
regurgitator-0.3.0 lib/regurgitator/domain_path.rb
regurgitator-0.2.0 lib/regurgitator/domain_path.rb