W3C home > Mailing lists > Public > www-jigsaw@w3.org > September to October 1997

Re: Possibly weird question regarding proxy setup

From: Martin Wille <m@ifib.uni-karlsruhe.de>
Date: Thu, 30 Oct 1997 16:35:08 +0100
Message-Id: <199710301535.QAA13232@ifib7.ifib.uni-karlsruhe.de>
To: orjan@ip.lu
cc: www-jigsaw@w3.org
> Hello!
> 
> I have a fairly weird question for you Jigsaw experts!
> 
> Is it possible to set up Jigsaw in such a way that it acts as
> a kind of half-proxy for another (hidden) WWW server? With half
> proxy I mean that:
> 
>  1) The user should not set up Jigsaw as a "normal" proxy in his browser
>     configuration. In stead, from the client point of view, it will look
>     like Jigsaw is the real server accessed.
> 
>  2) The real server runs behind Jigsaw and will get all its request 
>     forwarded, in a normal proxy manner, from Jigsaw. It should only 
>     accept request from Jigsaw, and nowhere else.
> 
> 
> So if a client requests
>   
>    http://jigsaw.server.somewhere/bla/blabla.html
> 
> it would first go to Jigsaw that in turn goes to its backend hidden 
> server at
> 
>    http://hidden.server.somewhere/bla/blabla.html
> 
> and fetches and relays the response back to the client.
> 
> The reason for this is A) I want to impelemnt some ACL stuff
> on the Jigsaw server, before the request is served (as a filter).
> and B) I would like to offer to our clients that they don't have
> to switch WWW server. So I just put Jigsaw in front of their server.
> 
> So what do you say? Possible or not?
> 
> Warm regards,
> /Orjan
> 
> 
> 
> Orjan Reinholdsen
> INFOPARTNERS S.A.
> Tel    +352 295759 3302
> Fax    +352 295759 3900
> email  orjan@ip.lu
> URL    http://www.ip.lu/
> 
Hi,

yes, it is possible if you subclass ForwardDirectory in a way like 
MirrorDirectotry does and add a properly configured resource of your
new class.
IMHO your request isn't weird at all.

Ad 1) In your special example MirrorDirectory will serve your needs and you 
won't need my solution. A more complex example would be:
   serving http://hidden.server/blah/foo
   as      http://jigsaw.server/gaga/bar

Ad 2) You will have to ensure that only jigsaw can access your hidden server 
by
using your hidden servers access control mechanisms (or by some weird other 
mechnisms)

Here an example (mostly copied from MirrorDirectory):
----- snip ------ snip -----
// MirrorURL.java

package whatever;

import java.net.*;
import java.io.*;

import w3c.tools.store.*;
import w3c.www.http.*;
import w3c.jigsaw.http.*;
import w3c.jigsaw.resources.*;
import w3c.jigsaw.proxy.*;

/**
 * Mirror a whole site, right there.
 */

public class MirrorURL extends ForwardDirectory {
    /**
     * Attribute index - The site we are mirroring.
     */
    protected static int ATTR_MIRRORS = -1;
    protected static int ATTR_REMOVEHEADER = -1;

    static {
	Class     c = null;
	Attribute a = null;
	try {
	    c = Class.forName("whetever.MirrorURL");
	} catch (Exception ex) {
	    ex.printStackTrace();
	    System.exit(1);
	}
	// Register the mirrored site attribute:
	a = new StringAttribute("mirrors"
				, null
				, Attribute.EDITABLE);
	ATTR_MIRRORS = AttributeRegistry.registerAttribute(c, a);
	a = new StringAttribute("remove-header"
				, null
				, Attribute.EDITABLE);
	ATTR_REMOVEHEADER = AttributeRegistry.registerAttribute(c, a);
    }

    protected URL mirrors = null;

    /**
     * Get the mirrors site attribute value.
     * @return The String encoded URL of the site we are mirroring here.
     */

    public String getMirrors() {
	return getString(ATTR_MIRRORS, null);
    }

    public String getRemoveHeader() {
	return getString(ATTR_REMOVEHEADER, null);
    }

    /**
     * Catch assignment to the mirror attribute, to update our cached URL.
     * @param idx The slot to set.
     * @param value It's new value.
     */

    public void setValue(int idx, Object value) {
	super.setValue(idx, value);
	if ( idx == ATTR_MIRRORS ) {
	    try {
		mirrors = new URL(getMirrors());
	    } catch (Exception ex) {
		mirrors = null;
	    }
	}
    }

    protected Reply dupReply(Request request
			     , w3c.www.protocol.http.Reply rep) 
	throws HTTPException, IOException
    {
	Reply reply = super.dupReply(request, rep);
	// Tweak redirections ! Wow this is getting real nifty :-)
	switch(reply.getStatus()) {
	  case HTTP.MOVED_PERMANENTLY:
	  case HTTP.MOVED_TEMPORARILY:
	  case HTTP.SEE_OTHER:
	      // Have fun !
	      String location = rep.getLocation();
	      if ((mirrors != null) && (location != null)) {
		  try {
		      URL uloc = new URL(mirrors, location);
		      URL loc  = getURL(request);
		      URL fake = new URL("http"
					 , loc.getHost()
					 , loc.getPort()
					 , uloc.getFile());
		      reply.setLocation(fake);
		  } catch (Exception ex) {
		  }
		  return reply;
	      }
	}
	return reply;
    }
    protected w3c.www.protocol.http.Request dupRequest(Request request) 
	throws HTTPException, IOException
    {
	w3c.www.protocol.http.Request req = super.dupRequest(request);
	// Tweak the URL :-)
	//req.setURL(new URL(mirrors, request.getURL().getFile()));
	String file=request.getURL().getFile();
	String removeheader=getRemoveHeader();
	if ((removeheader!=null) && file.startsWith(removeheader)) {
		file=file.substring(removeheader.length());
	}
	req.setURL(new URL(mirrors, file));
	//System.err.println("new url:"+(new URL(mirrors, file).toExternalForm()));
	//System.err.flush();
	return req;
    }
		
    /**
     * Lookup for a mirrored  resource.
     * @param request The request whose URI is to be looked up.
     * @exception HTTPException If something fails.
     */

    public boolean lookup(LookupState ls, LookupResult lr) 
	throws HTTPException
    {
	// Get the full URL from the request:
	Request request = ls.getRequest();
	URL     url     = request.getURL() ;
        boolean superResult = super.lookup(ls, lr);

	if ( ls.isInternal() )
	    return superResult;
	// Is this really belonging to the site we are mirroring ?
	if ( mirrors != null ) {
	    request.setProxy(true);
	    lr.setTarget(this);
	    return true;
	} 
	// Emit a not found:
	Reply error = request.makeReply(HTTP.NOT_FOUND);
	error.setContent("Target resource not found.");
	lr.setTarget(null);
	lr.setReply(error);
	return true;
    }

    public void initialize(Object values[]) {
	super.initialize(values);
	String strmirrors = getMirrors();
	try {
	    mirrors = new URL(strmirrors);
	} catch (Exception ex) {
	    mirrors = null;
	}
    }

}
----- snip ------ snip -----

In your example you would configure like this:
1) add a resource of class whatever.MirrorURL as /bla on your jigsaw server
2) set the mirrors attribute to http://hidden.server.somewhere/
3) leave the remove-header attribute empty

In my example you would coonfigure like this
1) add a resource of class whatever.MirrorURL as /blah/foo on your jigsaw 
server
2) set the mirror attribute to http://hidden.server/gaga/bar
3) set the remove-header attribute to /gaga/bar
You will have to ensure that links don't point to http://hidden.server.somewher
e
in an absolute manner.

Regards,
Martin Wille
Received on Thursday, 30 October 1997 10:36:14 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:26 GMT