Link to home
Start Free TrialLog in
Avatar of adinarayanak
adinarayanak

asked on

Location Tag Query

Hi All,
    I am planning to implement an URL redirector module(Let's say Socket server running at 7000), which takes the URL requests and redirects them to one of the other Servers but the PATH will be same. All these other servers will have their data bases replicated and they have same paged and procedures.

For example:
   User will connect to my server by typing http://abc.foo.com:7000/index.html on the browser. I read the request and I reconstruct the new URL as  http://def.foo.com:7777/index.html and redirects the browser to the new URL by sending 301 Status and by using Location:<newURL> Tag.
   
Now here are the questions.
1.  When I use the Location: tag syntax , the address on the address bar of the browser is getting replaced with http://def.foo.com:7777/index.html. Is it not possible keep this value on the address bar unchanged i,e http://abc.foo.com:7000/ ?  The PATH could be changed. Is there any way in which browser internally connects to http://def.foo.com:7777/index.html ?

2.  With the address changing behaviour of this URL redirection,  let's say there is a form on the page http://def.foo.com:7777/index.html . User will fill that form and submit to some procedure by giving href as http://abc.foo.com:7000/prodedure.
   My server running at port 7000 will construct a new URL http://ghi.foo.com:7777/procedure and redirects the browser to it. Will that data filled up by the user be available to this procedure on http://ghi.foo.com:7777 ?

-Adi.
Avatar of third
third
Flag of Philippines image

1. one option to preserve the address in the address bar is to use frames. two frames (top and bottom) which has zero (0%)percent-100% ratio.
Avatar of adinarayanak
adinarayanak

ASKER

Third,
  I am not that familier with web technologies. Could you please explain a bit more on that ?

-Adi.
Third,
  I am not that familier with web technologies. Could you please explain a bit more on that ?

-Adi.
Third,
  I am not that familier with web technologies. Could you please explain a bit more on that ?

-Adi.
Third,
  I am not that familier with web technologies. Could you please explain a bit more on that ?

-Adi.
sorry for the delayed response. i left so i cannot respond.

anyway, what im trying to say does not do the actual redirection. it's creates a trick so that the address above will stay the same while navigating the pages. it will be composed of a frameset having two frames. the top frame is zero-sized so that it will not be obvious that there is a frame on your page. it's like,

<HTML>
<FRAMESET ROWS="0%,100%">
<FRAME FRAMEBORDER="0" NORESIZE NAME="FrameA" SRC="http://abc.foo.com:7000/index.html">
<FRAME FRAMEBORDER="1" NORESIZE NAME="FrameB" SRC="http://def.foo.com:7777/index.html">
</FRAMESET>
</HTML>

when you process at the bottom page, the target frame should always be the bottom frame.
Third,
  I am not that familier with web technologies. Could you please explain a bit more on that ?

-Adi.
As you said, I don't think this will do actual redirection.  Could you please suggest some solution, which does actaual redirection but the name in the address bar should always be constant.

-Adi
other than that, sorry i can't help.

any reason why you would want it to happen like that?
If you are going to use Http redirects, this is not possible. As you mentioned ("by sending 301 Status"), the client receives a message to redirect to a new location... so, it is the client that makes a new request for the resource at the new location. Nothing server side would change that. In order for the address to remain the same using redirects, you would have to write a client that does that.

A better option is to look into something other than redirects.

-corey

Corey,
    Thanks for the info given.  I don't mind having the new URL on the address bar. Could you please give me some info the second question ?

-Adi
Hmm, for part two I don't think you'd be able to implement it quite that way. Let me first try to capture what I think you want as an end result:

1. user starts at page 1 served by server A
2. form submit is processed on server B
3. user sees results at page 2 served server A

Now, the problem with your method (submit directly to server B and serve results from server A) is that you would have to use a redirect to get from B back to A. This means a new request and, therefore, loss of any request attributes from the processing. You also lose any session attributes because they are stored on server B, so server A doesn't know about them.

However, I believe that you *can* find a number of ways to accomplish what you want if you tweak it a litle. For example, you could:

1. submit to server A
2. have server A submit to server B via some small, lightweight http client
3. have server A store the response values from server B in the request or session (on server A)
4. have server A redirect to a page served by itself that can gather the values from the request or session.

This solution would actually solve both issues (if I understand them correctly).

Really, the only change from the user's perspective is that the form submits to server A rather than server B. I don't imagine that's really a problem, but I could be wrong.

As for the http client, it can be fairly simple to write. I've got a *very* rudimentary one written in about 50 lines of Java.

-corey
Hi Corey,
     Thanks for your response.Let me explain my requirement. I have 3 servers(lets say A,B,C All of them have webservers installed on and they have their data bases in Sync.)

     Now I have to implement one intermediate server which should takes the request from the browser and send the request to one of the available above 3 servers.It should not redirect the browser. In that case what will happen is , lets say my server redirets the Browser to Server A. I will lose control over it. If Server A fails, I won't be able to do forward the user request to one of the other two available servers.

    So  I need to implement a proxy sort of thing I guess. Could you please give me some guidelined how to go a head. I would appreciate If you could give me  some Standard source code. So that I can modify it according to my need.

Thanks,
Adi.
Corey,
    It would be gteat If you could send me the code for lightweight HTTP client.
ASKER CERTIFIED SOLUTION
Avatar of coreyit
coreyit

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The problem in this HTTP client is,  it is not handling the the body part of HTTP packet(data submitted by user like forms,...).

Let's say user typed http://<url of load balancer >:7000/index.html.Assume that this index.html is some login page.  Now I parse the packet and construct new URL based on one of the back end servers.  I use your HTTP client, passing the new URL and I get the login page in the response. I send this page to the Browser. Till now it is fine.

  Now user enters username and password and clicks on submit button. Here the reference will be given to load balancer. So the HTTP request comes to Load balancer. It again constrcts a new URL and sends it to one of the servers using your client. Here the problem  is,  It is not sending the username and password to the backend servers. It is sending the URL and request type only.

   As there is no username and password, the backend server will again pops up with the same loging page. This process will get repeated infinitely.

   Is there any way in which I can send the form data to the back end servers ? That only will solve the problem.

-Adi.

   
So far that client only sends requests of type "GET". In that case, you would need to tack onto the url any form input:

http://backendserver/loginpage.aaa?user=me&pass=mypass

Otherwise the client would need to be modified to use "POST" requests and to send the form data appropriately. I haven't looked into that yet, but will take a look soon.

-corey
Note also that using a load balancer should keep you from having to use that client at all.

Load balancing links:
http://directory.google.com/Top/Computers/Software/Internet/Site_Management/Load_Balancing/?tc=1

-corey
Corey,
    Thanks for your help. I am planning to use the inbuilt load balancing feature of the Apache web server.
Based on the information regarding Proxy throughput Round-Robin method available,
I did the following configuration.

    In the Proxy Throughpult Round-Robin method for load balancing feature available in Apache web server,  The mapping rules are like this.
 
RewriteEngine on
RewriteMap    lb      prg:/path/to/lb.pl
RewriteRule   ^/(.+)$ ${lb:$1}           [P,L]
 
Where lb.pl is some thing like this.
 
#!/path/to/perl
##
##  lb.pl -- load balancing script
##

$| = 1;

$name   = "www";     # the hostname base
$first  = 1;         # the first server (not 0 here, because 0 is myself)
$last   = 5;         # the last server in the round-robin
$domain = "foo.dom"; # the domainname

$cnt = 0;
while (<STDIN>) {
    $cnt = (($cnt+1) % ($last+1-$first));
    $server = sprintf("%s%d.%s", $name, $cnt+$first, $domain);
    print "http://$server/$_";
}

##EOF##
 
It appends the path passed to it and constructs a new URL.
 
Is there any way In which I can send the cookie information to this perl script  as STDIN ?

Or is there any way in which I can access the Cookie information in this perl script ?

I am asking this question as a separate one. Please have a look.

-Adi.

cookies are embedded in the header of the http request.. so you should be able to retrieve them and direct each request appropriately.

CJ
Corey,
    I could implement the Load balancing using Orixy throughput method vailable with Apache. Thanks for all the information given to me.

CJ,
   yes , we can pass the Cookie info to the perl script. If we cange the line
"RewriteRule   ^/(.+)$ ${lb:$1}           [P,L]" to
"RewriteRule   ^/(.+)$ ${lb:$1:%{HTTP:Cookie}           [P,L]"

It will solve our problem.

Thanks.
Glad it worked out. Good luck and cheers!
-corey