W3C home > Mailing lists > Public > www-validator-cvs@w3.org > November 2011

2002/css-validator/org/w3c/css/util ApplContext.java,1.23,1.24 HTTPURL.java,1.24,1.25

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Thu, 03 Nov 2011 16:00:42 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1RLzic-0005do-0Q@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/util
In directory hutz:/tmp/cvs-serv21605/org/w3c/css/util

Modified Files:
	ApplContext.java HTTPURL.java 
Log Message:
Recast of Ville Skytt&auml; patch to add Referer, Fixes http://www.w3.org/Bugs/Public/show_bug.cgi?id=14634

Index: ApplContext.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/ApplContext.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- ApplContext.java	29 Sep 2011 09:08:59 -0000	1.23
+++ ApplContext.java	3 Nov 2011 16:00:39 -0000	1.24
@@ -73,6 +73,8 @@
     String faketext = null;
     URL fakeurl = null;
 
+    URL referrer = null;
+
     /**
      * Creates a new ApplContext
      */
@@ -489,4 +491,20 @@
         }
         return nsdefs.containsKey(prefix);
     }
+
+    /**
+     * Set the current referrer for possible linked style sheets
+     * @param referrer the referring URL
+     */
+    public void setReferrer(URL referrer) {
+        this.referrer = referrer;
+    }
+
+    /**
+     * get the referrer URL (or null if not relevant)
+     * @return an URL
+     */
+    public URL getReferrer() {
+        return referrer;
+    }
 }

Index: HTTPURL.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/util/HTTPURL.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- HTTPURL.java	23 Aug 2011 09:23:50 -0000	1.24
+++ HTTPURL.java	3 Nov 2011 16:00:39 -0000	1.25
@@ -153,7 +153,7 @@
 
     private static URLConnection getConnection(URL url, int count)
             throws IOException {
-        return getConnection(url, count, null);
+        return getConnection(url, null, count, null);
     }
 
 
@@ -191,13 +191,15 @@
         uConn.setHostnameVerifier(hv);
     }
 
-    private static URLConnection getConnection(URL url, int count,
+    private static URLConnection getConnection(URL url, URL referrer, int count,
                                                ApplContext ac)
             throws IOException {
         if (count > 5) {
             throw new ProtocolException("Server redirected too many " +
                     "times (5)");
         }
+        // add the referrer, if not the same as the target URL
+        URL ref = (url.equals(referrer) ? null : referrer);
 
         if (Util.servlet) {
             String protocol = url.getProtocol();
@@ -223,6 +225,10 @@
         // for the fun
         urlC.setRequestProperty("User-Agent",
                 "Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0");
+        // referrer
+        if (ref != null) {
+            urlC.setRequestProperty("Referer", ref.toExternalForm());
+        }
         // relay authorization information
         if (ac.getCredential() != null) {
             urlC.setRequestProperty("Authorization", ac.getCredential());
@@ -268,7 +274,7 @@
                 case 307:
                     try {
                         URL u = getURL(httpURL.getHeaderField("Location"));
-                        return getConnection(u, count + 1, ac);
+                        return getConnection(u, ref, count + 1, ac);
                     } finally {
                         httpURL.disconnect();
                     }
@@ -304,7 +310,7 @@
 
     public static URLConnection getConnection(URL url, ApplContext ac)
             throws IOException {
-        return getConnection(url, 0, ac);
+        return getConnection(url, ac.getReferrer(), 0, ac);
     }
 
     /* more madness */
Received on Thursday, 3 November 2011 16:00:54 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:47 UTC