proxy_stack 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +7 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/proxy_stack/config/config.rb +9 -0
- data/lib/proxy_stack/config/environments/development.rb +18 -0
- data/lib/proxy_stack/config/environments/production.rb +19 -0
- data/lib/proxy_stack/config/environments/staging.rb +20 -0
- data/lib/proxy_stack/config.ru +10 -0
- data/lib/proxy_stack/proxy_stack.rb +61 -0
- data/lib/proxy_stack/tasks/proxy_stack.rake +4 -0
- data/lib/proxy_stack.rb +12 -0
- data/spec/proxy_stack_spec.rb +11 -0
- data/spec/spec_helper.rb +13 -0
- metadata +80 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 <YOUR NAME HERE>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'pancake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "proxy_stack"
|
9
|
+
gem.summary = %Q{Simple Light weight proxy}
|
10
|
+
gem.email = "has.sox@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/hassox/proxy_stack"
|
12
|
+
gem.authors = ["Daniel Neighman", "Lincoln Stoll"]
|
13
|
+
gem.add_dependency "pancake", ">=0.1.24"
|
14
|
+
gem.files = FileList["[A-Z]*", "pancake.init", "{lib,spec,rails}/**/*"]
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require File.join(File.dirname(__FILE__), "lib", "proxy_stack")
|
23
|
+
Pancake.root = Pancake.get_root(__FILE__, "lib", "proxy_stack")
|
24
|
+
THIS_STACK = ProxyStack
|
25
|
+
ProxyStack.load_rake_tasks!(:master => true)
|
26
|
+
|
27
|
+
require 'spec/rake/spectask'
|
28
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
34
|
+
spec.libs << 'lib' << 'spec'
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "foo #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Pancake.logger.info "Loading Development Environment"
|
2
|
+
|
3
|
+
# Set the middleware lables to load
|
4
|
+
Pancake.stack_labels = [:development]
|
5
|
+
|
6
|
+
# Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
|
7
|
+
|
8
|
+
class ProxyStack
|
9
|
+
# include middleware for the development stack
|
10
|
+
# stack(:middleware_name).use(MiddlewareClass)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Add code to hooks. Default available hooks:
|
14
|
+
# :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
|
15
|
+
|
16
|
+
# ProxyStack.before_build_stack do
|
17
|
+
# # stuff to do
|
18
|
+
# end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Pancake.logger.info "Loading Production Environment"
|
2
|
+
|
3
|
+
# Set the middleware lables to load
|
4
|
+
Pancake.stack_labels = [:production]
|
5
|
+
|
6
|
+
Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
|
7
|
+
|
8
|
+
class ProxyStack
|
9
|
+
# include middleware for the development stack
|
10
|
+
# stack(:middleware_name).use(MiddlewareClass)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Add code to hooks. Default available hooks:
|
14
|
+
# :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
|
15
|
+
|
16
|
+
# ProxyStack.before_build_stack do
|
17
|
+
# # stuff to do
|
18
|
+
# end
|
19
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Pancake.logger.info "Loading Staging Environment"
|
2
|
+
|
3
|
+
# Set the middleware lables to load
|
4
|
+
Pancake.stack_labels = [:staging]
|
5
|
+
|
6
|
+
Pancake.handle_errors!(true) # uncomment to have the stack handle any errors that occur
|
7
|
+
|
8
|
+
class ProxyStack
|
9
|
+
# include middleware for the development stack
|
10
|
+
# stack(:middleware_name).use(MiddlewareClass)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Add code to hooks. Default available hooks:
|
14
|
+
# :before_build_stack, :before_mount_applications, :after_initialize_application, :after_build_stack
|
15
|
+
|
16
|
+
# ProxyStack.before_build_stack do
|
17
|
+
# # stuff to do
|
18
|
+
# end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'pancake'
|
2
|
+
require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "..", "proxy_stack")
|
3
|
+
|
4
|
+
# get the application to run. The applicadtion in the Pancake.start block
|
5
|
+
# is the master application. It will have all requests directed to it through the
|
6
|
+
# pancake middleware
|
7
|
+
# This should be a very minimal file, but should be used when any stand alone code needs to be included
|
8
|
+
app = Pancake.start(:root => Pancake.get_root(__FILE__)){ ProxyStack.stackup(:master => true) }
|
9
|
+
|
10
|
+
run app
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class ProxyStack
|
2
|
+
helpers do
|
3
|
+
def proxy_request!
|
4
|
+
path = request.path_info
|
5
|
+
|
6
|
+
unless request.query_string.empty?
|
7
|
+
path = "#{path}?#{request.env['QUERY_STRING']}"
|
8
|
+
end
|
9
|
+
|
10
|
+
meth = request.request_method.downcase
|
11
|
+
meth[0..0] = meth[0..0].upcase
|
12
|
+
|
13
|
+
req = Net::HTTP.const_get(meth).new(path)
|
14
|
+
|
15
|
+
extract_http_headers.each do |h,v|
|
16
|
+
req[h] = v
|
17
|
+
end
|
18
|
+
|
19
|
+
if req.request_body_permitted?
|
20
|
+
req.content_length = request.content_length
|
21
|
+
req.content_type = request.content_type
|
22
|
+
req.body_stream = request.body
|
23
|
+
end
|
24
|
+
|
25
|
+
resp = Net::HTTP.start(configuration.proxy_domain, configuration.proxy_port) do |h|
|
26
|
+
h.request(req)
|
27
|
+
end
|
28
|
+
self.status = resp.code.to_i
|
29
|
+
|
30
|
+
the_headers = []
|
31
|
+
resp.canonical_each{|h,v| the_headers << [h,v]}
|
32
|
+
self.headers.replace(Hash[the_headers])
|
33
|
+
|
34
|
+
headers.delete("Transfer-Encoding")
|
35
|
+
|
36
|
+
|
37
|
+
if headers["Location"]
|
38
|
+
headers["Location"] = File.join(base_url, URI.parse(headers['Location']).path)
|
39
|
+
end
|
40
|
+
resp.body
|
41
|
+
end
|
42
|
+
|
43
|
+
def extract_http_headers
|
44
|
+
out = {}
|
45
|
+
request.env.keys.each do |key|
|
46
|
+
if key. !~ /^(pancake|rack|content-length|transfer-encoding)/i
|
47
|
+
out[key] = request.env[key]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
out
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Pancake::MimeTypes.type_by_extension(:json).type_strings << "application/x-javascript"
|
55
|
+
|
56
|
+
publish :provides => [:any]
|
57
|
+
any "/(*proxy_path_segments)" do
|
58
|
+
proxy_request!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/lib/proxy_stack.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'pancake'
|
2
|
+
class ProxyStack < Pancake::Stacks::Short
|
3
|
+
add_root(__FILE__, "proxy_stack")
|
4
|
+
|
5
|
+
# Hook to use before we mount any applications
|
6
|
+
# before_mount_applications do
|
7
|
+
# end
|
8
|
+
|
9
|
+
initialize_stack
|
10
|
+
end
|
11
|
+
|
12
|
+
require ::File.join(Pancake.get_root(__FILE__, "proxy_stack"), "proxy_stack")
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'pancake'
|
4
|
+
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
require 'proxy_stack'
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
config.include(Rack::Test::Methods)
|
12
|
+
config.include(Pancake::Test::Matchers)
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: proxy_stack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Neighman
|
8
|
+
- Lincoln Stoll
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-11-22 00:00:00 +11:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: pancake
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.1.24
|
25
|
+
version:
|
26
|
+
description:
|
27
|
+
email: has.sox@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- LICENSE
|
34
|
+
- README
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- lib/proxy_stack.rb
|
41
|
+
- lib/proxy_stack/config.ru
|
42
|
+
- lib/proxy_stack/config/config.rb
|
43
|
+
- lib/proxy_stack/config/environments/development.rb
|
44
|
+
- lib/proxy_stack/config/environments/production.rb
|
45
|
+
- lib/proxy_stack/config/environments/staging.rb
|
46
|
+
- lib/proxy_stack/proxy_stack.rb
|
47
|
+
- lib/proxy_stack/tasks/proxy_stack.rake
|
48
|
+
- spec/proxy_stack_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/hassox/proxy_stack
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- --charset=UTF-8
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Simple Light weight proxy
|
78
|
+
test_files:
|
79
|
+
- spec/proxy_stack_spec.rb
|
80
|
+
- spec/spec_helper.rb
|