gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] storm/org/nongnu/storm/util HTTPProxy.java


From: Tuukka Hastrup
Subject: [Gzz-commits] storm/org/nongnu/storm/util HTTPProxy.java
Date: Thu, 08 May 2003 10:10:43 -0400

CVSROOT:        /cvsroot/storm
Module name:    storm
Changes by:     Tuukka Hastrup <address@hidden> 03/05/08 10:10:43

Modified files:
        org/nongnu/storm/util: HTTPProxy.java 

Log message:
        started reorg

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/util/HTTPProxy.java.diff?tr1=1.23&tr2=1.24&r1=text&r2=text

Patches:
Index: storm/org/nongnu/storm/util/HTTPProxy.java
diff -u storm/org/nongnu/storm/util/HTTPProxy.java:1.23 
storm/org/nongnu/storm/util/HTTPProxy.java:1.24
--- storm/org/nongnu/storm/util/HTTPProxy.java:1.23     Thu May  8 09:19:00 2003
+++ storm/org/nongnu/storm/util/HTTPProxy.java  Thu May  8 10:10:43 2003
@@ -46,30 +46,31 @@
     protected IndexedPool pool;
     protected int port;
     protected String addr;
-    protected String url;
+    protected String ROOTURL;
     protected String REWRITE;
     protected String URNPAC;
-
+    protected String BACKLINKS;
     protected HTTPServer server;
     
     public HTTPProxy(IndexedPool pool, int port) throws IOException {
        this.pool = pool;
        this.port = port;
        this.addr = InetAddress.getLocalHost().getHostName();
-       this.url = "http://"+addr+":"+port+"/";;
-       this.REWRITE = url+"rewrite/";
+       this.ROOTURL = "http://"+addr+":"+port+"/";;
+       this.REWRITE = "rewrite";
+       this.BACKLINKS = "backlinks";
        this.URNPAC = "urn-proxy.pac";
 
        this.server = new HTTPServer(new Factory(), port);
     }
 
     public void run() {
-       if(dbg) p("Starting Storm URN server @ "+url);
+       if(dbg) p("Starting Storm URN server @ "+ROOTURL);
        server.run();
     }
 
     public String getURL() {
-       return url;
+       return ROOTURL;
     }
     
     protected class StormConnection extends HTTPConnection {
@@ -85,7 +86,10 @@
                if(HTTPProxy.dbg) p("<"+port+"> GET: "+uri + " (" + 
this.getRemoteIPAddress() + ")");
 
                /* URN proxy requests start directly with "urn:" */
-               if(uri.startsWith("/")) uri = uri.substring(1);
+               if(!uri.startsWith("/")) 
+                   return serveBlock(uri, resf);
+               else
+                   uri = uri.substring(1);
 
                if(uri.equals(URNPAC)) {
                    return makePAC(req, resf);
@@ -117,7 +121,7 @@
                        i.hasNext();) {
                        BlockId id = (BlockId)i.next();
                        String s = id.getURI();
-                       if(rewrite) s = REWRITE + s;
+                       if(rewrite) s = ROOTURL+REWRITE+"/" + s;
                        w.write("<a href=\""+s+"\">"+id+"</a><br>\n");
                    }
                    w.write("</body></html>\n");
@@ -126,84 +130,83 @@
                }
 
                BlockId id = new BlockId(uri);
+
+               if((!rewrite && !backlinks) || 
+                  !id.getContentType().equals("text/html"))
+                   return serveBlock(uri, resf);
+
+
+               if(HTTPProxy.dbg) p("Start rewrite");
+
                Block block = pool.get(id);
                
                HTTPResponse resp = resf.makeResponse(200, "Ok");
                resp.setField("Content-Type", id.getContentType());
-               if((!rewrite && !backlinks) || 
-                  !id.getContentType().equals("text/html")) {
-                   int blocksize = CopyUtil.copy(block.getInputStream(),
-                                 resp.getOutputStream());
-                   if(HTTPProxy.dbg) p("<"+port+"> Serve: "+id + " (Size: " + 
-                       String.valueOf(blocksize) + ")");                   
-               } else {
-                   if(HTTPProxy.dbg) p("Start rewrite");
-
-                   String s = CopyUtil.readString(block.getInputStream());
-
-                   String prefix = "";
-
-                   if(rewrite) {
-                       prefix = REWRITE;
-                       if(backlinks) prefix += "backlinks/";
-
-                       String l = s.toLowerCase();
-                       int i = -1;
-                       while((i=l.indexOf("urn:x-storm:1.0:", i)) >= 0) {
-                           s = s.substring(0, i) + prefix + s.substring(i);
-                           l = s.toLowerCase();
-                           i += prefix.length() + 1;
-                       }
-                   }
 
-                   if(backlinks) {
-                       if(HTTPProxy.dbg) p("Getting HtmlLinkIndex.");
+               String s = CopyUtil.readString(block.getInputStream());
 
-                       HtmlLinkIndex idx = null;
-                       try {
-                           idx = 
(HtmlLinkIndex)pool.getIndex(HtmlLinkIndex.uri);
-                       } catch(NoSuchElementException _) {}
+               String prefix = "";
+
+               if(rewrite) {
+                   prefix = ROOTURL+REWRITE+"/";
+                   if(backlinks) prefix += BACKLINKS+"/";
+                   
+                   String l = s.toLowerCase(); // XXX Why this?
+                   int i = -1;
+                   while((i=l.indexOf("urn:x-storm:1.0:", i)) >= 0) {
+                       s = s.substring(0, i) + prefix + s.substring(i);
+                       l = s.toLowerCase(); // XXX and this?
+                       i += prefix.length() + 1;
+                   }
+               }
+
+               if(backlinks) {
+                   if(HTTPProxy.dbg) p("Getting HtmlLinkIndex.");
+                   
+                   HtmlLinkIndex idx = null;
+                   try {
+                       idx = (HtmlLinkIndex)pool.getIndex(HtmlLinkIndex.uri);
+                   } catch(NoSuchElementException _) {}
+                   
+                   if(HTTPProxy.dbg) p("HtmlLinkIndex = "+idx);
+                   
+                   if(idx != null) {
+                       if(HTTPProxy.dbg) p("Looking for links");
+                       Collector links = idx.getLinksTo(id);
                        
-                       if(HTTPProxy.dbg) p("HtmlLinkIndex = "+idx);
+                       try {
+                           // XXX Are we trying to wait for indexing?
+                           Thread.sleep(2000);
+                       } catch(InterruptedException _) {}
                        
-                       if(idx != null) {
-                           if(HTTPProxy.dbg) p("Looking for links");
-                           Collector links = idx.getLinksTo(id);
-                           
-                           try {
-                               // XXX Are we trying to wait for indexing?
-                               Thread.sleep(2000);
-                           } catch(InterruptedException _) {}
-                           
-                           if(HTTPProxy.dbg) p("Iter thru links");
-                           String t = "";
-                           synchronized(links) {
-                               for(Iterator iter=links.iterator(); 
+                       if(HTTPProxy.dbg) p("Iter thru links");
+                       String t = "";
+                       synchronized(links) {
+                           for(Iterator iter=links.iterator(); 
                                iter.hasNext();) {
-                                   HtmlLinkIndex.Link link = 
-                                       (HtmlLinkIndex.Link)iter.next();
-                                   if(HTTPProxy.dbg) p("Link: "+link.linkText);
-                                   t += "[<a 
href=\""+prefix+link.linkFrom.getURI()+
-                                       "\">"+link.linkText+"</a>]<br>";
-                               }
-                           }
-                           if(!t.equals("")) {
-                               int i = s.indexOf("<body");
-                               i = s.indexOf(">", i);
-                               if(i < 0) i = 0;
-                               else i++;
-                               s = s.substring(0, i) 
-                                   + "\n<p><small>Backlinks:<br>"
-                                   + t
-                                   + "</small></p>\n" 
-                                   + s.substring(i);
+                               HtmlLinkIndex.Link link = 
+                                   (HtmlLinkIndex.Link)iter.next();
+                               if(HTTPProxy.dbg) p("Link: "+link.linkText);
+                               t += "[<a 
href=\""+prefix+link.linkFrom.getURI()+
+                                   "\">"+link.linkText+"</a>]<br>";
                            }
                        }
+                       if(!t.equals("")) {
+                           int i = s.indexOf("<body");
+                           i = s.indexOf(">", i);
+                           if(i < 0) i = 0;
+                           else i++;
+                           s = s.substring(0, i) 
+                               + "\n<p><small>Backlinks:<br>"
+                               + t
+                               + "</small></p>\n" 
+                               + s.substring(i);
+                       }
                    }
-                       
-                   byte[] bytes = s.getBytes("US-ASCII");
-                   resp.getOutputStream().write(bytes);
                }
+                       
+               byte[] bytes = s.getBytes("US-ASCII");
+               resp.getOutputStream().write(bytes);
                return resp;
            } catch(FileNotFoundException e) {
                return resf.makeError(404, "Not found");
@@ -240,7 +243,22 @@
            w.write("<p>");
            w.write("To configure URN proxy in Netscape Navigator 4, ");
            w.write("Automatic Proxy Configuration location can be set to ");
-           w.write("<a href=\""+url+URNPAC+"\">"+url+URNPAC+"</a></p>\n");
+           w.write("<a href=\""+ROOTURL+URNPAC+"\">"
+                   +ROOTURL+URNPAC+"</a></p>\n");
+       }
+
+       protected HTTPResponse serveBlock(String uri, 
+                                         HTTPResponse.Factory resf) 
+           throws Exception {
+               BlockId id = new BlockId(uri);
+               Block block = pool.get(id);
+               
+               HTTPResponse resp = resf.makeResponse(200, "Ok");
+               resp.setField("Content-Type", id.getContentType());
+
+               int blocksize = CopyUtil.copy(block.getInputStream(),
+                                             resp.getOutputStream());
+               return resp;
        }
 
        protected HTTPResponse makePAC(HTTPRequest req, 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]