simple ruby proxy

M

Max Benjamin

Hello,
I'm trying to use a ruby program to grab html outside of my domain and
alter it for use in another page in my domain. This is a proxy, right?
I thought I wouldn't have a problem with this but... I do.
<%
require "cgi"
require "open-uri"

cgi = CGI.new()
url = cgi.params['myURL']

htmlDoc = ""
test = open(url)
test.each() do |line|
htmlDoc += line
end
%>
<%= htmlDoc %>
When I ask for this program in a GET request I'm asked if I want to save
the file rather than getting a display of the html. I'm sure this is
just some stupid noob mistake I'm making. Any help would be
appreciated.
Best,
Max
 
T

Timothy Goddard

Max said:
Hello,
I'm trying to use a ruby program to grab html outside of my domain and
alter it for use in another page in my domain. This is a proxy, right?
I thought I wouldn't have a problem with this but... I do.
<%
require "cgi"
require "open-uri"

cgi = CGI.new()
url = cgi.params['myURL']

htmlDoc = ""
test = open(url)
test.each() do |line|
htmlDoc += line
end
%>
<%= htmlDoc %>
When I ask for this program in a GET request I'm asked if I want to save
the file rather than getting a display of the html. I'm sure this is
just some stupid noob mistake I'm making. Any help would be
appreciated.
Best,
Max

OpenURI can be used to open files. A script like this would be a major
security problem. The problem here with being asked to save it is that
you aren't sending the proper MIME type. Look at the CGI docs for how
to do this.
 
M

Max Benjamin

Timothy said:
OpenURI can be used to open files. A script like this would be a major
security problem. The problem here with being asked to save it is that
you aren't sending the proper MIME type. Look at the CGI docs for how
to do this.

Ok, I'm still having some trouble getting this to work. I looked at the
cgi docs but find them a little daunting. Is there some example code
someone could point me to?
Thanks.
 
K

KDr2

Max Benjamin said:
Ok, I'm still having some trouble getting this to work. I looked at the
cgi docs but find them a little daunting. Is there some example code
someone could point me to?
Thanks.

Maybe an apache server with mod_ruby installed is what you needed,
google "mod_ruby" plz!

--
For some reasons,my EMail had been changed to "kdr2[#]163.com" now...

NO GNUS is Bad News.

------yours Killy Draw
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top