avdi-rack_base_uri 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack_base_uri.rb +4 -1
- data/spec/rack_base_uri_spec.rb +15 -1
- metadata +2 -2
data/lib/rack_base_uri.rb
CHANGED
@@ -13,9 +13,12 @@ module Rack
|
|
13
13
|
|
14
14
|
def call(env)
|
15
15
|
host = env.fetch('HTTP_HOST') {
|
16
|
-
env['
|
16
|
+
env['SERVER_NAME'] + ':' + env['SERVER_PORT']
|
17
17
|
}
|
18
18
|
base = host + env['SCRIPT_NAME']
|
19
|
+
unless base =~ %r[://]
|
20
|
+
base = (env['rack.url_scheme'] + '://' + base)
|
21
|
+
end
|
19
22
|
result = @app.call(env)
|
20
23
|
headers = result[1]
|
21
24
|
doc = Hpricot(result[2].to_s)
|
data/spec/rack_base_uri_spec.rb
CHANGED
@@ -23,12 +23,13 @@ describe Rack::BaseUri do
|
|
23
23
|
@app = stub("app", :call => @result)
|
24
24
|
@it = Rack::BaseUri.new(@app)
|
25
25
|
@base = 'http://example.org/subdir'
|
26
|
+
@host = 'http://example.org'
|
26
27
|
end
|
27
28
|
|
28
29
|
def do_request
|
29
30
|
@map = Rack::URLMap.new({@base => @it})
|
30
31
|
@request = Rack::MockRequest.new(@map)
|
31
|
-
@response = @request.get("/subdir/foo", 'HTTP_HOST' =>
|
32
|
+
@response = @request.get("/subdir/foo", 'HTTP_HOST' => @host)
|
32
33
|
@doc = Hpricot(@response.body)
|
33
34
|
end
|
34
35
|
|
@@ -40,6 +41,19 @@ describe Rack::BaseUri do
|
|
40
41
|
tag.should_not be_nil
|
41
42
|
tag['href'].should == "http://example.org/subdir"
|
42
43
|
end
|
44
|
+
|
45
|
+
describe "with a HTTP_HOST of example.org" do
|
46
|
+
before :each do
|
47
|
+
@host = "example.org"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should ensure base uri starts with URL scheme" do
|
51
|
+
do_request
|
52
|
+
@response.should be_ok
|
53
|
+
tag = @doc.at("head base")
|
54
|
+
tag['href'].should == "http://example.org/subdir"
|
55
|
+
end
|
56
|
+
end
|
43
57
|
end
|
44
58
|
describe "with application/xhtml+xml content type" do
|
45
59
|
before :each do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avdi-rack_base_uri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avdi Grimm
|
@@ -69,6 +69,6 @@ rubyforge_project:
|
|
69
69
|
rubygems_version: 1.2.0
|
70
70
|
signing_key:
|
71
71
|
specification_version: 2
|
72
|
-
summary: A Rack
|
72
|
+
summary: A Rack middleware for automatically setting [X]HTML document base URIs.
|
73
73
|
test_files: []
|
74
74
|
|