rack-proxy 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
- pkg
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-proxy.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-proxy (0.3.4)
5
+ rack
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ rack (1.2.1)
11
+ rack-test (0.5.6)
12
+ rack (>= 1.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ rack
19
+ rack-proxy!
20
+ rack-test
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
- require "rake/testtask"
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
2
3
 
4
+ require "rake/testtask"
3
5
  task :test do
4
6
  Rake::TestTask.new do |t|
5
7
  t.libs << "test"
@@ -9,20 +11,3 @@ task :test do
9
11
  end
10
12
 
11
13
  task :default => :test
12
-
13
- begin
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- gem.name = "rack-proxy"
17
- gem.summary = "A request/response rewriting HTTP proxy. A Rack app."
18
- gem.description = "A Rack app that provides request/response rewriting proxy capabilities with streaming."
19
- gem.email = "jacek.becela@gmail.com"
20
- gem.homepage = "http://github.com/ncr/rack-proxy"
21
- gem.authors = ["Jacek Becela"]
22
- gem.add_dependency "rack"
23
- gem.add_development_dependency "rack-test"
24
- end
25
- Jeweler::GemcutterTasks.new
26
- rescue LoadError
27
- puts "Jeweler not available. Install it with: gem install jeweler"
28
- end
data/Readme CHANGED
@@ -1 +1,25 @@
1
1
  A request/response rewriting HTTP proxy. A Rack app.
2
+
3
+ Subclass Rack::Proxy and provide your rewrite_env and rewrite_response methods.
4
+
5
+ Example:
6
+
7
+ class Foo < Rack::Proxy
8
+
9
+ def rewrite_env(env)
10
+ env["HTTP_HOST"] = "example.com"
11
+
12
+ env
13
+ end
14
+
15
+ def rewrite_response(triplet)
16
+ status, headers, body = triplet
17
+
18
+ headers["X-Foo"] = "Bar"
19
+
20
+ triplet
21
+ end
22
+
23
+ end
24
+
25
+ See tests for more examples.
@@ -11,6 +11,8 @@
11
11
  # but this is not real monkey patching.
12
12
  # I just added some methods and named them very uniquely
13
13
  # to avoid eventual conflicts. You're safe. Trust me.
14
+ #
15
+ # Also, in Ruby 1.9.2 you could use Fibers to avoid hacking net/http.
14
16
 
15
17
  require 'net/http'
16
18
 
@@ -0,0 +1 @@
1
+ require "rack/proxy"
@@ -5,6 +5,8 @@ module Rack
5
5
 
6
6
  # Subclass and bring your own #rewrite_request and #rewrite_response
7
7
  class Proxy
8
+ VERSION = "0.3.4"
9
+
8
10
  def call(env)
9
11
  rewrite_response(perform_request(rewrite_env(env)))
10
12
  end
@@ -47,7 +49,7 @@ module Rack
47
49
  headers = env.reject do |k, v|
48
50
  !(/^HTTP_[A-Z_]+$/ === k)
49
51
  end.map do |k, v|
50
- [k.sub(/^HTTP_/, ""), v]
52
+ [reconstruct_header_name(k), v]
51
53
  end.inject(Utils::HeaderHash.new) do |hash, k_v|
52
54
  k, v = k_v
53
55
  hash[k] = v
@@ -59,6 +61,10 @@ module Rack
59
61
  headers.merge!("X-Forwarded-For" => x_forwarded_for)
60
62
  end
61
63
 
64
+ def reconstruct_header_name(name)
65
+ name.sub(/^HTTP_/, "").gsub("_", "-")
66
+ end
67
+
62
68
  end
63
69
 
64
70
  end
@@ -1,57 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack-proxy"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{rack-proxy}
8
- s.version = "0.3.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Jacek Becela"]
12
- s.date = %q{2010-01-22}
6
+ s.name = "rack-proxy"
7
+ s.version = Rack::Proxy::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jacek Becela"]
10
+ s.email = ["jacek.becela@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/rack-proxy"
12
+ s.summary = %q{A request/response rewriting HTTP proxy. A Rack app.}
13
13
  s.description = %q{A Rack app that provides request/response rewriting proxy capabilities with streaming.}
14
- s.email = %q{jacek.becela@gmail.com}
15
- s.files = [
16
- ".gitignore",
17
- "Rakefile",
18
- "Readme",
19
- "VERSION",
20
- "lib/net_http_hacked.rb",
21
- "lib/rack/http_streaming_response.rb",
22
- "lib/rack/proxy.rb",
23
- "rack-proxy.gemspec",
24
- "test/http_streaming_response_test.rb",
25
- "test/net_http_hacked_test.rb",
26
- "test/rack_proxy_test.rb",
27
- "test/test_helper.rb"
28
- ]
29
- s.homepage = %q{http://github.com/ncr/rack-proxy}
30
- s.rdoc_options = ["--charset=UTF-8"]
31
- s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.3.5}
33
- s.summary = %q{A request/response rewriting HTTP proxy. A Rack app.}
34
- s.test_files = [
35
- "test/http_streaming_response_test.rb",
36
- "test/net_http_hacked_test.rb",
37
- "test/rack_proxy_test.rb",
38
- "test/test_helper.rb"
39
- ]
40
14
 
41
- if s.respond_to? :specification_version then
42
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
- s.specification_version = 3
15
+ s.rubyforge_project = "rack-proxy"
44
16
 
45
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- s.add_runtime_dependency(%q<rack>, [">= 0"])
47
- s.add_development_dependency(%q<rack-test>, [">= 0"])
48
- else
49
- s.add_dependency(%q<rack>, [">= 0"])
50
- s.add_dependency(%q<rack-test>, [">= 0"])
51
- end
52
- else
53
- s.add_dependency(%q<rack>, [">= 0"])
54
- s.add_dependency(%q<rack-test>, [">= 0"])
55
- end
56
- end
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
57
21
 
22
+ s.add_dependency("rack")
23
+ s.add_development_dependency("rack-test")
24
+ end
@@ -19,4 +19,14 @@ class RackProxyTest < Test::Unit::TestCase
19
19
  assert last_response.ok?
20
20
  assert /Jacek Becela/ === last_response.body
21
21
  end
22
+
23
+ def test_header_reconstruction
24
+ proxy = Rack::Proxy.new
25
+
26
+ header = proxy.send(:reconstruct_header_name, "HTTP_ABC")
27
+ assert header == "ABC"
28
+
29
+ header = proxy.send(:reconstruct_header_name, "HTTP_ABC_D")
30
+ assert header == "ABC-D"
31
+ end
22
32
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 4
10
+ version: 0.3.4
5
11
  platform: ruby
6
12
  authors:
7
13
  - Jacek Becela
@@ -9,31 +15,40 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-01-22 00:00:00 +01:00
18
+ date: 2010-11-04 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: rack
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
23
32
  version: "0"
24
- version:
33
+ type: :runtime
34
+ version_requirements: *id001
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: rack-test
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
33
46
  version: "0"
34
- version:
47
+ type: :development
48
+ version_requirements: *id002
35
49
  description: A Rack app that provides request/response rewriting proxy capabilities with streaming.
36
- email: jacek.becela@gmail.com
50
+ email:
51
+ - jacek.becela@gmail.com
37
52
  executables: []
38
53
 
39
54
  extensions: []
@@ -42,10 +57,12 @@ extra_rdoc_files: []
42
57
 
43
58
  files:
44
59
  - .gitignore
60
+ - Gemfile
61
+ - Gemfile.lock
45
62
  - Rakefile
46
63
  - Readme
47
- - VERSION
48
64
  - lib/net_http_hacked.rb
65
+ - lib/rack-proxy.rb
49
66
  - lib/rack/http_streaming_response.rb
50
67
  - lib/rack/proxy.rb
51
68
  - rack-proxy.gemspec
@@ -54,30 +71,36 @@ files:
54
71
  - test/rack_proxy_test.rb
55
72
  - test/test_helper.rb
56
73
  has_rdoc: true
57
- homepage: http://github.com/ncr/rack-proxy
74
+ homepage: http://rubygems.org/gems/rack-proxy
58
75
  licenses: []
59
76
 
60
77
  post_install_message:
61
- rdoc_options:
62
- - --charset=UTF-8
78
+ rdoc_options: []
79
+
63
80
  require_paths:
64
81
  - lib
65
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
66
84
  requirements:
67
85
  - - ">="
68
86
  - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
69
90
  version: "0"
70
- version:
71
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
72
93
  requirements:
73
94
  - - ">="
74
95
  - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
75
99
  version: "0"
76
- version:
77
100
  requirements: []
78
101
 
79
- rubyforge_project:
80
- rubygems_version: 1.3.5
102
+ rubyforge_project: rack-proxy
103
+ rubygems_version: 1.3.7
81
104
  signing_key:
82
105
  specification_version: 3
83
106
  summary: A request/response rewriting HTTP proxy. A Rack app.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.3