Sha256: 9e870d9a98e995a3ae10454c64ede18482e3e8246e0d1b6b218db0095aa082ea

Contents?: true

Size: 580 Bytes

Versions: 1

Compression:

Stored size: 580 Bytes

Contents

class WithOrWithoutWWW
  
  def initialize(app, with=true, excluded=['localhost'])
    @app, @with, @excluded = app, with, excluded
  end

  def call(env)
    req = Rack::Request.new(env)
    return @app.call(env) if @excluded.include?(req.host)
    if !@with && req.host[/^www./]
      [301, {"Location" => req.url.sub("//www.", "//"), 'Content-Type'=>'text/html'}, self]
    elsif @with && !req.host[/^www./]
      [301, {"Location" => req.url.sub("//", "//www."), 'Content-Type'=>'text/html'}, self]
    else
      @app.call(env)
    end
  end
  
  def each(&block); end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
with-or-without-www-0.0.2 with_or_without_www.rb