uzuuzu-core 0.1.14 → 0.1.15
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/VERSION +1 -1
- data/lib/uzuuzu-core/response.rb +70 -0
- data/uzuuzu-core.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.15
|
data/lib/uzuuzu-core/response.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
2
5
|
|
3
6
|
module UzuUzu
|
4
7
|
#
|
@@ -91,6 +94,73 @@ module UzuUzu
|
|
91
94
|
throw :finish
|
92
95
|
end # redirect
|
93
96
|
|
97
|
+
#
|
98
|
+
#
|
99
|
+
#
|
100
|
+
def reverse_proxy(url, opts={})
|
101
|
+
uri = URI.parse(url)
|
102
|
+
headers = opts['headers'] if opts['headers']
|
103
|
+
headers ||= opts[:headers] if opts[:headers]
|
104
|
+
headers ||= Rack::Utils::HeaderHash.new
|
105
|
+
request.env.each do |key, value|
|
106
|
+
if key =~ /HTTP_(.*)/
|
107
|
+
headers[$1] = value
|
108
|
+
end
|
109
|
+
end
|
110
|
+
headers['HOST'] = uri.host unless (opts[:host] || opts['host'])
|
111
|
+
Net::HTTP.version_1_2
|
112
|
+
http = Net::HTTP.new( uri.host, uri.port )
|
113
|
+
http.read_timeout = opts[:timeout] if opts[:timeout]
|
114
|
+
http.read_timeout = opts['timeout'] if opts['timeout']
|
115
|
+
if uri.scheme == 'https' && (opts[:ssl] || opts['ssl'])
|
116
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
117
|
+
else
|
118
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
119
|
+
end
|
120
|
+
http.start do |http|
|
121
|
+
m = request.request_method
|
122
|
+
case m
|
123
|
+
when 'GET', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'
|
124
|
+
req = Net::HTTP.const_get(m.capitalize).new("#{uri.path}?#{uri.query}", headers)
|
125
|
+
req.basic_auth opts[:username], opts[:password] if opts[:username] and opts[:password]
|
126
|
+
req.basic_auth opts['username'], opts['password'] if opts['username'] and opts['password']
|
127
|
+
when 'PUT', 'POST'
|
128
|
+
req = Net::HTTP.const_get(m.capitalize).new("#{uri.path}?#{uri.query}", headers)
|
129
|
+
req.basic_auth opts[:username], opts[:password] if opts[:username] and opts[:password]
|
130
|
+
req.basic_auth opts['username'], opts['password'] if opts['username'] and opts['password']
|
131
|
+
|
132
|
+
if request.body.respond_to?(:read) && request.body.respond_to?(:rewind)
|
133
|
+
body = request.body.read
|
134
|
+
req.content_length = body.size
|
135
|
+
request.body.rewind
|
136
|
+
else
|
137
|
+
req.content_length = request.body.size
|
138
|
+
end
|
139
|
+
|
140
|
+
req.content_type = request.content_type unless request.content_type.nil?
|
141
|
+
req.body_stream = request.body
|
142
|
+
else
|
143
|
+
raise "method not supported: #{m}"
|
144
|
+
end # case m
|
145
|
+
|
146
|
+
body = ''
|
147
|
+
res = http.request(req) do |res|
|
148
|
+
res.read_body do |segment|
|
149
|
+
body << segment
|
150
|
+
end
|
151
|
+
end
|
152
|
+
response_headers = Rack::Utils::HeaderHash.new(res.to_hash)
|
153
|
+
response_headers.delete('status')
|
154
|
+
response_headers.delete('transfer-encoding')
|
155
|
+
response_headers.each do |key, value|
|
156
|
+
response.header[key] = value
|
157
|
+
end
|
158
|
+
response.status = 200
|
159
|
+
response.body = [body]
|
160
|
+
end # http
|
161
|
+
|
162
|
+
throw :finish
|
163
|
+
end
|
94
164
|
#
|
95
165
|
#
|
96
166
|
#
|
data/uzuuzu-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{uzuuzu-core}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.15"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Takuya Kondo"]
|
12
|
-
s.date = %q{2012-
|
12
|
+
s.date = %q{2012-03-17}
|
13
13
|
s.description = %q{uzuuzu core library}
|
14
14
|
s.email = %q{takuya_v_v@uzuuzu.jp}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: uzuuzu-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.15
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Takuya Kondo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-03-17 00:00:00 +09:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -201,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
201
|
requirements:
|
202
202
|
- - ">="
|
203
203
|
- !ruby/object:Gem::Version
|
204
|
-
hash: -
|
204
|
+
hash: -3658651349859392470
|
205
205
|
segments:
|
206
206
|
- 0
|
207
207
|
version: "0"
|