Class: Regurgitator::DomainHost
- Inherits:
-
Object
- Object
- Regurgitator::DomainHost
- Includes:
- Endpoint
- Defined in:
- lib/regurgitator/domain_host.rb
Overview
Matches GET and HEAD requests in the format of “:domain.example.com/:dkey” where domain is read from the Host: header.
If a client were to make a request to “foo.example.com/bar”, this endpoint would respond with the file from the “foo” domain with the key “bar”. To use as middleware:
require 'regurgitator'
db = Sequel.connect('mysql2://[email protected]/mogilefs')
use Regurgitator::DomainHost, :suffix => '.example.com', :db => db
See the domain_host.ru example for a standalone app.
Instance Method Summary collapse
-
#call(env) ⇒ Object
:nodoc:.
-
#initialize(app, opts) ⇒ DomainHost
constructor
:nodoc:.
Methods included from Endpoint
#best_addr, #empty_file, #endpoint_init, #filename!, #reproxy_path, #serve_file, #serve_info
Methods included from FileInfo
Methods included from Device
#device_init, #device_uris!, extended, #refresh_device, #refresh_device_unlocked
Methods included from ServerSettings
extended, #refresh_zone, #refresh_zone_unlocked, #server_settings_init, #zone_for
Methods included from Domain
#domain_init, #get_dmid, #refresh_domain, #refresh_domain_unlocked
Constructor Details
#initialize(app, opts) ⇒ DomainHost
:nodoc:
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/regurgitator/domain_host.rb', line 21 def initialize(app, opts) # :nodoc: case suffix = opts[:suffix] when String suffix = Regexp.quote(suffix) suffix = %r{\A(.*)#{suffix}\z} when Regexp else raise TypeError, ":suffix must be a String or Regexp #{suffix.inspect}" end @domain_regexp = suffix endpoint_init(app, opts[:db], opts[:reproxy_key]) end |
Instance Method Details
#call(env) ⇒ Object
:nodoc:
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/regurgitator/domain_host.rb', line 34 def call(env) # :nodoc: case env['REQUEST_METHOD'] when 'GET', 'HEAD' host = env['HTTP_HOST'] or return @app.call(env) domain = @domain_regexp =~ host ? $1 : host serve_file(env, domain, env['PATH_INFO'][1..-1]) else @app.call(env) end end |