Sha256: f5f5271b64f03774a4e807c376e2de649fb2b927df71671998dc15a2e10b939e

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 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, db) # :nodoc:
    super(app, Hash === db ? db[:db] : db)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
regurgitator-0.0.0 lib/regurgitator/domain_path.rb