Class: UWA::Proxy

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

Instance Method Summary collapse

Instance Method Details

#process(req, res) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/uwa/proxy.rb', line 8

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 req.params['REMOTE_ADDR'] == '127.0.0.1'
			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