Solved

Location Tag Query

Posted on 2002-04-17
22
217 Views
Last Modified: 2013-11-19
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.
0
Comment
Question by:adinarayanak
  • 12
  • 6
  • 3
  • +1
22 Comments
 
LVL 30

Expert Comment

by:third
ID: 6949933
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.
0
 

Author Comment

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

-Adi.
0
 

Author Comment

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

-Adi.
0
 

Author Comment

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

-Adi.
0
 

Author Comment

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

-Adi.
0
 
LVL 30

Expert Comment

by:third
ID: 6952284
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.
0
 

Author Comment

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

-Adi.
0
 

Author Comment

by:adinarayanak
ID: 6952516
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
0
 
LVL 30

Expert Comment

by:third
ID: 6952543
other than that, sorry i can't help.

any reason why you would want it to happen like that?
0
 
LVL 2

Expert Comment

by:coreyit
ID: 6952552
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

0
 

Author Comment

by:adinarayanak
ID: 6952579
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
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Expert Comment

by:coreyit
ID: 6955072
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
0
 

Author Comment

by:adinarayanak
ID: 6955643
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.
0
 

Author Comment

by:adinarayanak
ID: 6955647
Corey,
    It would be gteat If you could send me the code for lightweight HTTP client.
0
 
LVL 2

Accepted Solution

by:
coreyit earned 100 total points
ID: 6956934
Here is the client. Note that it is *very* rudimentary. It only sends "GET" requests, has next to no error handling, and uses a deprecated method. I just whipped it up recently as a quick example. You should definitely improve it before putting it to work.

---- HttpClient.java ----
import java.net.*;
import java.io.*;
import java.util.*;

public class HttpClient {

    public HttpClient( String url ) {
        _url = url;
        _res = null;
    }
   
    public String getResponse() {
        return _res.toString();
    }

    public void run() {

        URLConnection connection;
        int length;
        try {
            URL url = new URL( _url );
            connection = url.openConnection();
            connection.setRequestProperty( "method", "GET" );
            connection.setUseCaches( false );
            connection.setDoOutput ( true );

            // Check our response code
            int code = ( (HttpURLConnection) connection ).getResponseCode();
            switch( code ) {
                case 200: // HTTP_OK
                    String blah;
                    _res = new StringBuffer();
                    DataInputStream input = new DataInputStream( connection.getInputStream() );
                    while( ( blah = input.readLine() ) != null ) {
                        _res.append( blah );
                        _res.append( "\n" );
                    }
                    input.close();
                    input = null;
                    break;
                default: // some other
                    _res.append( "oops! got this response code: " );
                    _res.append( code );
            }
        }
        catch( IOException e ) {
            e.printStackTrace();
        }
    }

    private String _url;
    private StringBuffer _res;
}
--------

As for your requirements, you may just want to look into a load balancer setup. In that way, request would always go through the load balanced URL but could be processed by multiple underlying machines. If one of the machines is down, the load balancer would direct traffic to the other two.

-corey
0
 

Author Comment

by:adinarayanak
ID: 6957644
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.

   
0
 
LVL 2

Expert Comment

by:coreyit
ID: 6958397
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
0
 
LVL 2

Expert Comment

by:coreyit
ID: 6958421
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
0
 

Author Comment

by:adinarayanak
ID: 6959711
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.

0
 
LVL 19

Expert Comment

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

CJ
0
 

Author Comment

by:adinarayanak
ID: 6960085
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.
0
 
LVL 2

Expert Comment

by:coreyit
ID: 6960702
Glad it worked out. Good luck and cheers!
-corey
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now