HTTP traffic over a custom proxy server?

K

Knorpi

Hi,

I would like to setup a server "myserver" that acts as a proxy for its clients. The clients pass the url of the web page they want in a query string:

- client sends a HTTP request:
http://myserver?url=www.foreignurl.com&par2=val1

- Servlet on myserver extracts url from query string:
www.foreignurl.com

- Servlet sends HTTP request to other server with query string:
http://www.foreignurl.com?par1=val1

- Servlet renders complete response from other server
into a String "content"

- Servlet changes every link in the content to point to myserver
so that all links are accessed the same way

- Servlet sends response to client

The most important part would be to change all links in the response.
Can you give me some hints how to do this?

Thanks
Magnus
 
T

Tom Anderson

I would like to setup a server "myserver" that acts as a proxy for its
clients. The clients pass the url of the web page they want in a query
string:

- client sends a HTTP request:
http://myserver?url=www.foreignurl.com&par2=val1

- Servlet on myserver extracts url from query string:
www.foreignurl.com

- Servlet sends HTTP request to other server with query string:
http://www.foreignurl.com?par1=val1

This seems a mildly odd way of doing this. As Stefan suggests, it might be
better to do whatever it is you're doing as a normal, proper, proxy
server.
- Servlet renders complete response from other server
into a String "content"

- Servlet changes every link in the content to point to myserver
so that all links are accessed the same way

- Servlet sends response to client

The most important part would be to change all links in the response.
Can you give me some hints how to do this?

If you're going to do it properly, you really need to parse the HTML,
identify all the a elements which have hrefs, rewrite each of those, and
write out the modified HTML. Doing this in the face of bad HTML, and doing
it in such a way that it won't radically alter the pages, may be quite
tricky.

tom
 
R

Roedy Green

The most important part would be to change all links in the response.
Can you give me some hints how to do this?

What is the advantage of doing this? Without some sort of caching, it
seems all you get is extra overhead.
--
Roedy Green Canadian Mind Products
http://mindprod.com
One of the great annoyances in programming derives from the irregularity
of English spelling especially when you have international teams.
I want to find a method or variable, but I don't know precisely
how its is spelled or worded. English is only approximately phonetic.
Letters are randomly doubled. The dictionary often lists variant spellings.
British, Canadian and American spellings differ.I would like to see an
experiment where variable names were spelled in a simplified English, where
there were no double letters.I also think you could add a number of rules
about composing variable names so that a variable name for something would
be highly predictable. You would also need automated enforcement of the
rules as well as possible.
 
E

Esmond Pitt

The most important part would be to change all links in the response.

Why? If the client knows about the proxy, the proxy will get all the
link requests, and it just needs to do what it is already doing.

And change them to *what* exactly?
 
S

Silvio

Hi,

I would like to setup a server "myserver" that acts as a proxy for its clients. The clients pass the url of the web page they want in a query string:

- client sends a HTTP request:
http://myserver?url=www.foreignurl.com&par2=val1

- Servlet on myserver extracts url from query string:
www.foreignurl.com

- Servlet sends HTTP request to other server with query string:
http://www.foreignurl.com?par1=val1

Sounds like a proxy on drugs...
- Servlet renders complete response from other server
into a String "content"

- Servlet changes every link in the content to point to myserver
so that all links are accessed the same way

This is not generally possible. A page might use JavaScript to generate
URLs dynamcally and you would not be able to hook into that.

You can use the <base href="..."/> tag for achieving something similar
for relative URLs.

Ceating a proper proxy and setting it as the proxy for the user agents
would solve this automatically.

Silvio
 

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

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top