Class: Canonical::Middleware
- Inherits:
-
Object
- Object
- Canonical::Middleware
- Defined in:
- lib/rack-canonical-header/middleware.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 6 |
# File 'lib/rack-canonical-header/middleware.rb', line 3 def initialize(app) @app = app @status, @headers, @body = nil end |
Class Method Details
.canonical_tag(env, canonical_host) ⇒ Object
18 19 20 21 22 |
# File 'lib/rack-canonical-header/middleware.rb', line 18 def self.canonical_tag(env, canonical_host) url_scheme = env['HTTP_X_FORWARDED_PROTO'] || env['rack.url_scheme'] canonical = "#{url_scheme}://#{canonical_host}#{env['ORIGINAL_FULLPATH']}" "<#{canonical}>; rel=\"canonical\"" end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/rack-canonical-header/middleware.rb', line 8 def call(env) @status, @headers, @body = @app.call(env) canonical_host = ENV['CANONICAL_HOST'] return [@status, @headers, @body] unless html? && canonical_host @headers['Link'] = Middleware.canonical_tag(env, canonical_host) [@status, @headers, @body] end |