Skip to content

Commit

Permalink
Prepare for v0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jun 16, 2015
1 parent 631f47d commit 189870c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Lotus::Router
Rack compatible HTTP router for Ruby

## v0.4.1 - 2015-06-23
### Added
- [Alfonso Uceda Pompa] Force SSL (eg `Lotus::Router.new(force_ssl: true`).
- [Alfonso Uceda Pompa] Allow router to accept a `:prefix` option, in order to generate prefixed routes.

## v0.4.0 - 2015-05-15
### Added
- [Alfonso Uceda Pompa] Nested RESTful resource(s)
Expand Down
2 changes: 1 addition & 1 deletion lib/lotus/router/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Lotus
class Router
# @since 0.1.0
VERSION = '0.4.0'.freeze
VERSION = '0.4.1'.freeze
end
end
58 changes: 29 additions & 29 deletions lib/lotus/routing/force_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,91 +6,91 @@ module Routing
#
# Redirect response to the secure equivalent resource (https)
#
# @since x.x.x
# @since 0.4.1
# @api private
class ForceSsl
# Https scheme
#
# @since x.x.x
# @since 0.4.1
# @api private
SSL_SCHEME = 'https'.freeze

# @since x.x.x
# @since 0.4.1
# @api private
HTTPS = 'HTTPS'.freeze

# @since x.x.x
# @since 0.4.1
# @api private
ON = 'on'.freeze

# Location header
#
# @since x.x.x
# @since 0.4.1
# @api private
LOCATION_HEADER = 'Location'.freeze

# Default http port
#
# @since x.x.x
# @since 0.4.1
# @api private
DEFAULT_HTTP_PORT = 80

# Default ssl port
#
# @since x.x.x
# @since 0.4.1
# @api private
DEFAULT_SSL_PORT = 443

# Moved Permanently http code
#
# @since x.x.x
# @since 0.4.1
# @api private
MOVED_PERMANENTLY_HTTP_CODE = 301

# Temporary Redirect http code
#
# @since x.x.x
# @since 0.4.1
# @api private
TEMPORARY_REDIRECT_HTTP_CODE = 307

# @since x.x.x
# @since 0.4.1
# @api private
HTTP_X_FORWARDED_SSL = 'HTTP_X_FORWARDED_SSL'.freeze

# @since x.x.x
# @since 0.4.1
# @api private
HTTP_X_FORWARDED_SCHEME = 'HTTP_X_FORWARDED_SCHEME'.freeze

# @since x.x.x
# @since 0.4.1
# @api private
HTTP_X_FORWARDED_PROTO = 'HTTP_X_FORWARDED_PROTO'.freeze

# @since x.x.x
# @since 0.4.1
# @api private
HTTP_X_FORWARDED_PROTO_SEPARATOR = ','.freeze

# @since x.x.x
# @since 0.4.1
# @api private
RACK_URL_SCHEME = 'rack.url_scheme'.freeze

# @since x.x.x
# @since 0.4.1
# @api private
REQUEST_METHOD = 'REQUEST_METHOD'.freeze

# @since x.x.x
# @since 0.4.1
# @api private
IDEMPOTENT_METHODS = ['GET', 'HEAD'].freeze

EMPTY_BODY = ''.freeze

# Initialize ForceSsl.
#
# @param force [Boolean] activate redirection to SSL
# @param active [Boolean] activate redirection to SSL
# @param options [Hash] set of options
# @option options [String] :host
# @option options [Integer] :port
#
# @since x.x.x
# @since 0.4.1
# @api private
def initialize(active, options = {})
@active = active
Expand All @@ -108,7 +108,7 @@ def initialize(active, options = {})
#
# @see Lotus::Routing::HttpRouter#call
#
# @since x.x.x
# @since 0.4.1
# @api private
def call(env)
end
Expand All @@ -117,37 +117,37 @@ def call(env)
#
# @return [Boolean]
#
# @since x.x.x
# @since 0.4.1
# @api private
def force?(env)
!ssl?(env)
end

private

# @since x.x.x
# @since 0.4.1
# @api private
attr_reader :host

# Return full url to redirect
#
# @param request [Rack::Request] a Rack request
# @param env [Hash] Rack env
#
# @return [String]
#
# @since x.x.x
# @since 0.4.1
# @api private
def full_url(env)
"#{ SSL_SCHEME }://#{ host }:#{ port }#{ ::Rack::Request.new(env).fullpath }"
end

# Return redirect code
#
# @param request [Rack::Request] a Rack request
# @param env [Hash] Rack env
#
# @return [Integer]
#
# @since x.x.x
# @since 0.4.1
# @api private
def redirect_code(env)
if IDEMPOTENT_METHODS.include?(env[REQUEST_METHOD])
Expand All @@ -161,7 +161,7 @@ def redirect_code(env)
#
# @return [Integer]
#
# @since x.x.x
# @since 0.4.1
# @api private
def port
if @port == DEFAULT_HTTP_PORT
Expand All @@ -171,7 +171,7 @@ def port
end
end

# @since x.x.x
# @since 0.4.1
# @api private
def _redefine_call
return unless @active
Expand All @@ -183,7 +183,7 @@ def _redefine_call

# Adapted from Rack::Request#scheme
#
# @since x.x.x
# @since 0.4.1
# @api private
def scheme(env)
if env[HTTPS] == ON
Expand All @@ -199,7 +199,7 @@ def scheme(env)
end
end

# @since x.x.x
# @since 0.4.1
# @api private
def ssl?(env)
scheme(env) == SSL_SCHEME
Expand Down
12 changes: 6 additions & 6 deletions lib/lotus/routing/http_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def url(route, *args)
#
# @see Lotus::Router#options
#
# @since x.x.x
# @since 0.4.1
# @api private
def get(path, options = {}, &blk)
super(@prefix.join(path), options, &blk)
Expand All @@ -103,7 +103,7 @@ def get(path, options = {}, &blk)
#
# @see Lotus::Router#post
#
# @since x.x.x
# @since 0.4.1
# @api private
def post(path, options = {}, &blk)
super(@prefix.join(path), options, &blk)
Expand All @@ -113,7 +113,7 @@ def post(path, options = {}, &blk)
#
# @see Lotus::Router#put
#
# @since x.x.x
# @since 0.4.1
# @api private
def put(path, options = {}, &blk)
super(@prefix.join(path), options, &blk)
Expand All @@ -123,7 +123,7 @@ def put(path, options = {}, &blk)
#
# @see Lotus::Router#patch
#
# @since x.x.x
# @since 0.4.1
# @api private
def patch(path, options = {}, &blk)
super(@prefix.join(path), options, &blk)
Expand All @@ -133,7 +133,7 @@ def patch(path, options = {}, &blk)
#
# @see Lotus::Router#delete
#
# @since x.x.x
# @since 0.4.1
# @api private
def delete(path, options = {}, &blk)
super(@prefix.join(path), options, &blk)
Expand All @@ -143,7 +143,7 @@ def delete(path, options = {}, &blk)
#
# @see Lotus::Router#trace
#
# @since x.x.x
# @since 0.4.1
# @api private
def trace(path, options = {}, &blk)
super(@prefix.join(path), options, &blk)
Expand Down
2 changes: 1 addition & 1 deletion test/version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

describe Lotus::Router::VERSION do
it 'exposes version' do
Lotus::Router::VERSION.must_equal '0.4.0'
Lotus::Router::VERSION.must_equal '0.4.1'
end
end

0 comments on commit 189870c

Please sign in to comment.