Class: UWA::Proxy

Inherits:
Mongrel::HttpHandler
  • Object
show all
Defined in:
lib/uwa/proxy.rb

Constant Summary collapse

@@ALLOWED_IP =
[ '127.0.0.1' ]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allow(ip) ⇒ Object



9
10
11
# File 'lib/uwa/proxy.rb', line 9

def self.allow(ip)
	@@ALLOWED_IP << ip
end

Instance Method Details

#process(req, res) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/uwa/proxy.rb', line 13

def process(req,res)
	query = CGI::parse(req.params['QUERY_STRING'].to_s)
	url = query['url'].to_a.first
	if url.nil?
		UWA::Server.log :ignore, req.params['REQUEST_URI']
	else
		url = URI.parse(query['url'].to_a.first.to_s.strip)
		if @@ALLOWED_IP.include? req.params['REMOTE_ADDR']
			res.start(200) do |head, out|
			head["Content-Type"] = "text/xml"
			unless url.nil?
				UWA::Server.log :proxy, url
				res = Net::HTTP.start(url.host, url.port) do |http|
					http.get(url.request_uri)
				end
				out.write(res.body)
			end
			end
		else
			UWA::Server.log :denied, "#{url} from #{req.params['REMOTE_ADDR']}"
		end
	end
end