rack-ie-redirect-fix 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-ie-redirect-fix.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ require "rack-ie-redirect-fix/version"
2
+ require 'uri'
3
+
4
+ module Rack
5
+ class IeRedirectFix
6
+ def initialize app
7
+ @app = app
8
+ end
9
+
10
+ def call env
11
+ status, headers, body = @app.call env
12
+
13
+ if status.to_i == 302
14
+ uri = URI.parse headers['Location']
15
+ if uri.scheme == "http" and uri.host == env['SERVER_NAME']
16
+ uri.scheme = 'https'
17
+ body_str = %Q{<html><body>You are being <a href="#{uri.to_s}">redirected</a>.</body></html>}
18
+
19
+ headers = headers.merge 'Location' => uri.to_s,
20
+ 'Content-Length' => body_str.size.to_s # The RSpec tests don't pick this up, but this is necessary
21
+ body = [body_str]
22
+ end
23
+ end
24
+
25
+ [status, headers, body]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class IeRedirectFix
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack-ie-redirect-fix/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-ie-redirect-fix"
7
+ s.version = Rack::IeRedirectFix::VERSION
8
+ s.authors = ["Mike Nicholaides"]
9
+ s.email = ["mike@ablegray.com"]
10
+ s.homepage = "https://github.com/nicholaides/rack-ie-redirect-fix"
11
+ s.summary = %q{Fixes an obscure issue with redirects that happens with IE and SSL}
12
+ s.description = %q{}
13
+
14
+ s.rubyforge_project = "rack-ie-redirect-fix"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "rack-test"
24
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::IeRedirectFix do
4
+ let(:app) do
5
+ Rack::IeRedirectFix.new(lambda{|env| rack_response })
6
+ end
7
+ let(:response){ get 'http://other-example.com/' }
8
+ subject{ response }
9
+
10
+ context "given a non-redirect" do
11
+ let(:status) { 200 }
12
+ let(:headers){ { "Content-Type" => 'text/plain' } }
13
+ let(:body) { "hi" }
14
+
15
+ let(:rack_response){ [status, headers, [body]] }
16
+
17
+ its(:status){ should == status }
18
+ its(:body) { should == body }
19
+
20
+ it "should leave the headers alone" do
21
+ headers.each do |name, value|
22
+ response.headers[name].should == value
23
+ end
24
+ end
25
+ end
26
+
27
+ context "given a to our app" do
28
+ let(:location) { 'http://other-example.com/some/path' }
29
+ let(:rack_response){ [302, { "Content-Type" => 'text/plain', 'Location' => location }, ["Some body"]] }
30
+
31
+ let(:expected_location){ 'https://other-example.com/some/path' }
32
+ let(:expected_body) { %Q{<html><body>You are being <a href="#{expected_location}">redirected</a>.</body></html>} }
33
+
34
+ it "should set the location to an SSL version of that URL" do
35
+ response.headers['Location'].should == expected_location
36
+ end
37
+
38
+ it "should set the appropriate content length" do
39
+ response.headers['Content-Length'].should == expected_body.size.to_s
40
+ end
41
+
42
+ its(:status){ should == 302 }
43
+ its(:body) { should == expected_body }
44
+ end
45
+
46
+ context "given a redirect an external URL" do
47
+ let(:location) { 'http://google.com/some/path.html' }
48
+ let(:headers) { { "Content-Type" => 'text/plain', 'Location' => location } }
49
+ let(:body) { "Redirecting to somewhere" }
50
+ let(:rack_response){ [302, headers, [body]] }
51
+
52
+ its(:status){ should == 302 }
53
+ its(:body) { should == body }
54
+ it "should leave the headers alone" do
55
+ headers.each do |name, value|
56
+ response.headers[name].should == value
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,12 @@
1
+ require "rubygems"
2
+ require "rspec"
3
+ require "rack/test"
4
+
5
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__)) + '/lib'
6
+ $LOAD_PATH.unshift File.dirname(File.dirname(__FILE__))
7
+
8
+ require "rack-ie-redirect-fix"
9
+
10
+ RSpec.configure do |config|
11
+ config.include Rack::Test::Methods
12
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-ie-redirect-fix
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Mike Nicholaides
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-09 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack-test
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: ""
50
+ email:
51
+ - mike@ablegray.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - .rspec
61
+ - Gemfile
62
+ - Rakefile
63
+ - lib/rack-ie-redirect-fix.rb
64
+ - lib/rack-ie-redirect-fix/version.rb
65
+ - rack-ie-redirect-fix.gemspec
66
+ - spec/ie_redirect_fix_spec.rb
67
+ - spec/spec_helper.rb
68
+ has_rdoc: true
69
+ homepage: https://github.com/nicholaides/rack-ie-redirect-fix
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project: rack-ie-redirect-fix
98
+ rubygems_version: 1.5.2
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Fixes an obscure issue with redirects that happens with IE and SSL
102
+ test_files:
103
+ - spec/ie_redirect_fix_spec.rb
104
+ - spec/spec_helper.rb