Class: Rack::HostMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/contrib/host_meta.rb

Overview

Rack middleware implementing the IETF draft: “Host Metadata for the Web” including support for Link-Pattern elements as described in the IETF draft: “Link-based Resource Descriptor Discovery.”

Usage:

use Rack::HostMeta do
  link :uri => '/robots.txt', :rel => 'robots'
  link :uri => '/w3c/p3p.xml', :rel => 'privacy', :type => 'application/p3p.xml'
  link :pattern => '{uri};json_schema', :rel => 'describedby', :type => 'application/x-schema+json'
end

See also:

http://tools.ietf.org/html/draft-nottingham-site-meta
http://tools.ietf.org/html/draft-hammer-discovery

TODO:

Accept POST operations allowing downstream services to register themselves

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ HostMeta

Returns a new instance of HostMeta.



24
25
26
27
28
29
# File 'lib/rack/contrib/host_meta.rb', line 24

def initialize(app, &block)
  @app = app
  @lines = []
  instance_eval(&block)
  @response = @lines.join("\n")
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rack/contrib/host_meta.rb', line 31

def call(env)
  if env['PATH_INFO'] == '/host-meta'
    [200, {'content-type' => 'application/host-meta'}, [@response]]
  else
    @app.call(env)
  end
end