refraction 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -11
- data/VERSION +1 -1
- data/lib/refraction.rb +4 -0
- data/refraction.gemspec +3 -4
- metadata +9 -21
- data/init.rb +0 -1
data/README.md
CHANGED
@@ -64,12 +64,32 @@ example, in nginx, that is done with a `server_name _;` directive.
|
|
64
64
|
|
65
65
|
Set up your rewrite/redirection rules during your app initialization using `Refraction.configure`.
|
66
66
|
The `configure` method takes a block which is run for every request to process the rules. The block
|
67
|
-
is passed a
|
68
|
-
|
67
|
+
is passed a request object that contains information about the request URL and environment. The
|
68
|
+
request is an instance of Refraction::Request, which is a subclass of Rack::Request. That means it has
|
69
|
+
all the standard Rack::Request methods for examining the request environment, headers, url components,
|
70
|
+
and so on, plus a few more for convenience.
|
71
|
+
|
72
|
+
### URL components
|
73
|
+
|
74
|
+
The request object provides the following components of the URL for matching requests: `scheme`,
|
75
|
+
`host`, `port`, `path`, and `query`. It also provides a full environment hash as the `env`
|
76
|
+
attribute. For example, `req.env['HTTP_USER_AGENT']` can be used to access the request's user
|
77
|
+
agent property. And other Rack::Request methods such as `ip` and `xhr?` are also available.
|
78
|
+
|
79
|
+
## Taking Action
|
80
|
+
|
81
|
+
The request object includes a small API for effecting rewrites and redirects. You should only use
|
82
|
+
one action method per request. That isn't enforced, but the effects will be unpredictable.
|
69
83
|
|
70
84
|
> Important note: don't do a `return` from within the configuration
|
71
85
|
> block. That would be bad (meaning your entire application would
|
72
|
-
> break). That's just how blocks work in Ruby
|
86
|
+
> break). That's just how blocks work in Ruby - you can only return from
|
87
|
+
> them once, not on every request.
|
88
|
+
|
89
|
+
There are two ways to specify the new location or URL: as a string or as an options hash of components.
|
90
|
+
If you use a string then that becomes the literal value for the redirect location or the rewritten
|
91
|
+
URL. If you use a hash, you can modify one or several of the URL components and leave the others
|
92
|
+
unchanged.
|
73
93
|
|
74
94
|
### `RequestContext#set(options)`
|
75
95
|
|
@@ -84,7 +104,15 @@ header.
|
|
84
104
|
|
85
105
|
Any URL components not explicitly set remain unchanged from the original request URL. You can use
|
86
106
|
`set` before calls to `rewrite!`, `permanent!`, or `found!` to set common values. Subsequent
|
87
|
-
methods will merge their component values into values from `set`.
|
107
|
+
action methods will merge their component values into values from `set`.
|
108
|
+
|
109
|
+
Note: If you change the URL scheme or host, any non-standard port will be reset to the default port
|
110
|
+
for the scheme unless specified. In the following example the first line will reset the port to the
|
111
|
+
default (that is, 80), but the second line will retain any non-standard port.
|
112
|
+
|
113
|
+
if req.path =~ %r{^/images} then req.found! :host => "assets.#{req.host}" end
|
114
|
+
if req.path =~ %r{^/images} then req.found! :host => "assets.#{req.host}", :port => req.port end
|
115
|
+
|
88
116
|
|
89
117
|
### `RequestContext#rewrite!(options)`
|
90
118
|
|
@@ -117,17 +145,11 @@ The args are largely the same as the contents of a standard Rack response array
|
|
117
145
|
that you don't need to wrap the content in an array, and the Content-Length header is generated so it
|
118
146
|
should not be supplied.
|
119
147
|
|
120
|
-
### URL components
|
121
|
-
|
122
|
-
The request object provides the following components of the URL for matching requests: `scheme`,
|
123
|
-
`host`, `port`, `path`, and `query`. It also provides a full environment hash as the `env`
|
124
|
-
attribute. For example, `req.env['HTTP_USER_AGENT']` can be used to access the request's user
|
125
|
-
agent property.
|
126
|
-
|
127
148
|
## Contributors
|
128
149
|
|
129
150
|
* Josh Susser (maintainer)
|
130
151
|
* Sam Pierson
|
131
152
|
* Wai Lun Mang
|
132
153
|
* Brian Morearty
|
154
|
+
* Dennis Collinson
|
133
155
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/refraction.rb
CHANGED
@@ -5,6 +5,8 @@ class Refraction
|
|
5
5
|
|
6
6
|
class Request < Rack::Request
|
7
7
|
attr_reader :action, :status, :message
|
8
|
+
|
9
|
+
# backward compatibility: support URI::HTTP component names
|
8
10
|
def method; request_method; end
|
9
11
|
def query; query_string; end
|
10
12
|
|
@@ -61,11 +63,13 @@ class Refraction
|
|
61
63
|
@re_location || url
|
62
64
|
end
|
63
65
|
|
66
|
+
# use original request's values when not set explicitly
|
64
67
|
def scheme; @re_scheme || super; end
|
65
68
|
def host; @re_host || super; end
|
66
69
|
def path; @re_path || super; end
|
67
70
|
def query_string; @re_query || super; end
|
68
71
|
|
72
|
+
# changing the scheme or host means use default port instead of port in original request
|
69
73
|
def port
|
70
74
|
@re_port || ((@re_scheme || @re_host) && default_port) || super
|
71
75
|
end
|
data/refraction.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{refraction}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Pivotal Labs", "Josh Susser", "Sam Pierson", "Wai Lun Mang"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-01}
|
13
13
|
s.description = %q{Reflection is a Rails plugin and standalone Rack middleware library. Give up quirky config syntax and use plain old Ruby for your rewrite and redirection rules.}
|
14
14
|
s.email = %q{gems@pivotallabs.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
"Rakefile",
|
22
22
|
"VERSION",
|
23
23
|
"geminstaller.yml",
|
24
|
-
"init.rb",
|
25
24
|
"install.rb",
|
26
25
|
"lib/refraction.rb",
|
27
26
|
"refraction.gemspec",
|
@@ -31,7 +30,7 @@ Gem::Specification.new do |s|
|
|
31
30
|
s.homepage = %q{http://github.com/pivotal/refraction}
|
32
31
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
32
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
33
|
+
s.rubygems_version = %q{1.3.5}
|
35
34
|
s.summary = %q{Rack middleware replacement for mod_rewrite}
|
36
35
|
s.test_files = [
|
37
36
|
"spec/refraction_spec.rb",
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refraction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 4
|
9
|
-
version: 0.1.4
|
4
|
+
version: 0.2.0
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Pivotal Labs
|
@@ -17,23 +12,19 @@ autorequire:
|
|
17
12
|
bindir: bin
|
18
13
|
cert_chain: []
|
19
14
|
|
20
|
-
date: 2010-
|
15
|
+
date: 2010-02-01 00:00:00 -08:00
|
21
16
|
default_executable:
|
22
17
|
dependencies:
|
23
18
|
- !ruby/object:Gem::Dependency
|
24
19
|
name: rspec
|
25
|
-
|
26
|
-
|
20
|
+
type: :development
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
23
|
requirements:
|
28
24
|
- - ">="
|
29
25
|
- !ruby/object:Gem::Version
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 2
|
33
|
-
- 9
|
34
26
|
version: 1.2.9
|
35
|
-
|
36
|
-
version_requirements: *id001
|
27
|
+
version:
|
37
28
|
description: Reflection is a Rails plugin and standalone Rack middleware library. Give up quirky config syntax and use plain old Ruby for your rewrite and redirection rules.
|
38
29
|
email: gems@pivotallabs.com
|
39
30
|
executables: []
|
@@ -48,7 +39,6 @@ files:
|
|
48
39
|
- Rakefile
|
49
40
|
- VERSION
|
50
41
|
- geminstaller.yml
|
51
|
-
- init.rb
|
52
42
|
- install.rb
|
53
43
|
- lib/refraction.rb
|
54
44
|
- refraction.gemspec
|
@@ -67,20 +57,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
57
|
requirements:
|
68
58
|
- - ">="
|
69
59
|
- !ruby/object:Gem::Version
|
70
|
-
segments:
|
71
|
-
- 0
|
72
60
|
version: "0"
|
61
|
+
version:
|
73
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
63
|
requirements:
|
75
64
|
- - ">="
|
76
65
|
- !ruby/object:Gem::Version
|
77
|
-
segments:
|
78
|
-
- 0
|
79
66
|
version: "0"
|
67
|
+
version:
|
80
68
|
requirements: []
|
81
69
|
|
82
70
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.3.
|
71
|
+
rubygems_version: 1.3.5
|
84
72
|
signing_key:
|
85
73
|
specification_version: 3
|
86
74
|
summary: Rack middleware replacement for mod_rewrite
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "refraction"
|