No commit activity in last 3 years
No release in over 3 years
Rack middleware for ensuring only proper hosts get passed to your application
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Rack::EnsureProperHost Build Status

Inspired by rack-no-www.


Usage

All of these examples will redirect all requests from *.example.com to example.com. Requests to secure.example.com will remain untouched.

Rack::EnsureProperHost is middleware. Use it like this in your rack applications:

Rails

# config/application.rb
module MyApp
  class Application < Rails::Application

    config.middleware.insert_before Rack::Lock, Rack::EnsureProperHost, %w(example.com secure.example.com)
        
  end
end

Sinatra

require 'sinatra'
require 'rack/ensure_proper_host'

use Rack::EnsureProperHost, %w(example.com secure.example.com)

get '/hello' do
  'Hello World'
end

Rack

Add the following to your config.ru

# config.ru
require 'your_app.rb'
require 'rack/ensure_proper_host'

use Rack::EnsureProperHost, %w(example.com secure.example.com)
run YourApp.new

Installation

As usual, just use the gem install command:

(sudo) gem install rack-ensure_proper_host

Or add Rack::EnsureProperHost as a gem in your Gemfile:

gem 'rack-ensure_proper_host', '~> 0.1.0' 

Then run bundle install


Testing

Testing is done with minitest. Run the tests with:

rake

Changelog

2012/1/20 - v0.1.0

  • it exists!

License

Copyright (c) 2011 - 2012 Spencer Steffen & Citrus, released under the New BSD License All rights reserved.