Index: org/w3c/css/css/CssParser.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/CssParser.java,v retrieving revision 1.6 diff -u -r1.6 CssParser.java --- org/w3c/css/css/CssParser.java 14 Sep 2005 15:14:17 -0000 1.6 +++ org/w3c/css/css/CssParser.java 31 Oct 2011 18:38:53 -0000 @@ -60,7 +60,7 @@ * @param origin the origin of the style sheet * @exception IOException an IO error */ - public void parseURL(ApplContext ac, URL url, String title, String kind, + public void parseURL(ApplContext ac, URL url, URL referrer, String title, String kind, String media, int origin); /** Index: org/w3c/css/css/CssValidator.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/CssValidator.java,v retrieving revision 1.14 diff -u -r1.14 CssValidator.java --- org/w3c/css/css/CssValidator.java 3 Oct 2011 17:07:08 -0000 1.14 +++ org/w3c/css/css/CssValidator.java 31 Oct 2011 18:38:53 -0000 @@ -140,7 +140,7 @@ // that it is a valid // url DocumentParser URLparser = new DocumentParser(style.ac, - uri); + uri, null); style.handleRequest(style.ac, uri, URLparser.getStyleSheet(), (String) style.params.get("output"), Index: org/w3c/css/css/DocumentParser.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/DocumentParser.java,v retrieving revision 1.9 diff -u -r1.9 DocumentParser.java --- org/w3c/css/css/DocumentParser.java 30 Oct 2011 21:00:32 -0000 1.9 +++ org/w3c/css/css/DocumentParser.java 31 Oct 2011 18:38:53 -0000 @@ -42,32 +42,38 @@ * * @throws Exception An error */ - public DocumentParser(ApplContext ac, String urlString) throws Exception { + public DocumentParser(ApplContext ac, String urlString, String refererString) throws Exception { this.htmlURL = HTTPURL.getURL(urlString); this.ac = ac; urlString = htmlURL.toString(); String urlLower = urlString.toLowerCase(); String media = ac.getMedium(); String urlProtocol = htmlURL.getProtocol(); - + URL referrer = null; + if (refererString != null) { + try { + referrer = HTTPURL.getURL(refererString); + } catch (IOException ignored) {} + } + if (!"http".equals(urlProtocol) && !"https".equals(urlProtocol)) { if (urlLower.endsWith(".css")) { StyleSheetParser parser = new StyleSheetParser(); - parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR); + parser.parseURL(ac, htmlURL, referrer, null, null, media, StyleSheetOrigin.AUTHOR); style = parser.getStyleSheet(); } else if (urlLower.endsWith(".html") || urlLower.endsWith(".htm") || urlLower.endsWith(".shtml") || urlLower.endsWith("/")) { //TagSoupStyleSheetHandler handler = new TagSoupStyleSheetHandler(htmlURL, ac); HTMLParserStyleSheetHandler handler = new HTMLParserStyleSheetHandler(htmlURL, ac); - handler.parse(htmlURL); + handler.parse(htmlURL, referrer); style = handler.getStyleSheet(); if (style != null) { style.setType("text/html"); } } else if (urlLower.endsWith(".xhtml") || urlLower.endsWith(".xml")) { - // Seems like we need to use tagsout in this case as well + // Seems like we need to use tagsoup in this case as well XMLStyleSheetHandler handler = new XMLStyleSheetHandler(htmlURL, ac); - handler.parse(htmlURL); + handler.parse(htmlURL, referrer); style = handler.getStyleSheet(); if (style != null) { style.setType("text/xml"); @@ -85,7 +91,7 @@ // @@ hum, maybe? (plh, yes probably :-) ) String credential = ac.getCredential(); - connection = HTTPURL.getConnection(htmlURL, ac); + connection = HTTPURL.getConnection(htmlURL, referrer, ac); htmlURL = connection.getURL(); String httpCL = connection.getHeaderField("Content-Location"); @@ -122,7 +128,7 @@ } } else if (contentType.match(MimeType.TEXT_CSS) == MimeType.MATCH_SPECIFIC_SUBTYPE) { StyleSheetParser parser = new StyleSheetParser(); - parser.parseURL(ac, htmlURL, null, null, media, StyleSheetOrigin.AUTHOR); + parser.parseURL(ac, htmlURL, referrer, null, null, media, StyleSheetOrigin.AUTHOR); style = parser.getStyleSheet(); } else if ((contentType.match(MimeType.TEXT_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE) || (contentType.match(MimeType.APPLICATION_XHTML_XML) == MimeType.MATCH_SPECIFIC_SUBTYPE) Index: org/w3c/css/css/HTMLParserStyleSheetHandler.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/HTMLParserStyleSheetHandler.java,v retrieving revision 1.2 diff -u -r1.2 HTMLParserStyleSheetHandler.java --- org/w3c/css/css/HTMLParserStyleSheetHandler.java 31 Oct 2011 18:32:19 -0000 1.2 +++ org/w3c/css/css/HTMLParserStyleSheetHandler.java 31 Oct 2011 18:38:53 -0000 @@ -206,6 +206,7 @@ } styleSheetParser.parseURL(ac, url, + documentURI, atts.get("title"), rel, media, @@ -327,6 +328,7 @@ } styleSheetParser.parseURL(ac, url, + documentURI, atts.getValue("title"), rel, media, @@ -549,7 +551,7 @@ } } - void parse(URL url) throws Exception { + void parse(URL url, URL referrer) throws Exception { InputSource source = new InputSource(); URLConnection connection; InputStream in; @@ -570,7 +572,7 @@ } xmlParser.setContentHandler(this); - connection = HTTPURL.getConnection(url, ac); + connection = HTTPURL.getConnection(url, referrer, ac); in = HTTPURL.getInputStream(ac, connection); String streamEncoding = HTTPURL.getCharacterEncoding(ac, connection); Index: org/w3c/css/css/StyleSheetParser.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/StyleSheetParser.java,v retrieving revision 1.23 diff -u -r1.23 StyleSheetParser.java --- org/w3c/css/css/StyleSheetParser.java 24 Oct 2011 19:49:03 -0000 1.23 +++ org/w3c/css/css/StyleSheetParser.java 31 Oct 2011 18:38:53 -0000 @@ -169,7 +169,7 @@ * @param origin the origin of the style sheet * @throws IOException an IO error */ - public void parseURL(ApplContext ac, URL url, String title, + public void parseURL(ApplContext ac, URL url, URL referrer, String title, String kind, String media, int origin) { setWarningLevel(ac.getWarningLevel()); @@ -189,7 +189,7 @@ try { ac.setOrigin(origin); // if (cssFouffa == null) { - cssFouffa = new CssFouffa(ac, url); + cssFouffa = new CssFouffa(ac, url, referrer); cssFouffa.addListener(this); // } else { // cssFouffa.ReInit(ac, url); Index: org/w3c/css/css/TagSoupStyleSheetHandler.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/TagSoupStyleSheetHandler.java,v retrieving revision 1.10 diff -u -r1.10 TagSoupStyleSheetHandler.java --- org/w3c/css/css/TagSoupStyleSheetHandler.java 31 Oct 2011 18:32:19 -0000 1.10 +++ org/w3c/css/css/TagSoupStyleSheetHandler.java 31 Oct 2011 18:38:53 -0000 @@ -203,6 +203,7 @@ } styleSheetParser.parseURL(ac, url, + documentURI, atts.get("title"), rel, media, @@ -322,6 +323,7 @@ } styleSheetParser.parseURL(ac, url, + documentURI, atts.getValue("title"), rel, media, @@ -541,7 +543,7 @@ } } - void parse(URL url) throws Exception { + void parse(URL url, URL referrer) throws Exception { InputSource source = new InputSource(); URLConnection connection; InputStream in; @@ -562,7 +564,7 @@ } xmlParser.setContentHandler(this); - connection = HTTPURL.getConnection(url, ac); + connection = HTTPURL.getConnection(url, referrer, ac); in = HTTPURL.getInputStream(ac, connection); String streamEncoding = HTTPURL.getCharacterEncoding(ac, connection); Index: org/w3c/css/css/XMLStyleSheetHandler.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/css/XMLStyleSheetHandler.java,v retrieving revision 1.33 diff -u -r1.33 XMLStyleSheetHandler.java --- org/w3c/css/css/XMLStyleSheetHandler.java 31 Oct 2011 18:32:19 -0000 1.33 +++ org/w3c/css/css/XMLStyleSheetHandler.java 31 Oct 2011 18:38:53 -0000 @@ -200,7 +200,7 @@ if (media == null && ac.getCssVersion() != CssVersion.CSS1) { media = "all"; } - styleSheetParser.parseURL(ac, url, atts.get("title"), rel, media, + styleSheetParser.parseURL(ac, url, documentURI, atts.get("title"), rel, media, StyleSheetOrigin.AUTHOR); if (Util.onDebug) { System.err.println("[parsed!]"); @@ -300,7 +300,7 @@ if (media == null && ac.getCssVersion() != CssVersion.CSS1) { media = "all"; } - styleSheetParser.parseURL(ac, url, atts.getValue("title"), + styleSheetParser.parseURL(ac, url, documentURI, atts.getValue("title"), rel, media, StyleSheetOrigin.AUTHOR); if (Util.onDebug) { System.err.println("[parsed!]"); @@ -477,7 +477,7 @@ } } - void parse(URL url) throws Exception { + void parse(URL url, URL referrer) throws Exception { InputSource source = new InputSource(); URLConnection connection; InputStream in; @@ -500,7 +500,7 @@ } xmlParser.setContentHandler(this); - connection = HTTPURL.getConnection(url, ac); + connection = HTTPURL.getConnection(url, referrer, ac); in = HTTPURL.getInputStream(ac, connection); String streamEncoding = HTTPURL.getCharacterEncoding(ac, connection); Index: org/w3c/css/parser/CssFouffa.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/CssFouffa.java,v retrieving revision 1.58 diff -u -r1.58 CssFouffa.java --- org/w3c/css/parser/CssFouffa.java 21 Oct 2011 12:52:29 -0000 1.58 +++ org/w3c/css/parser/CssFouffa.java 31 Oct 2011 18:38:53 -0000 @@ -152,8 +152,8 @@ * import) * @throws IOException if an I/O error occurs. */ - public CssFouffa(ApplContext ac, URL file) throws IOException { - this(ac, HTTPURL.getConnection(file, ac)); + public CssFouffa(ApplContext ac, URL file, URL referrer) throws IOException { + this(ac, HTTPURL.getConnection(file, referrer, ac)); } @@ -292,7 +292,7 @@ is = ac.getFakeInputStream(file); url = file; } else { - URLConnection urlC = HTTPURL.getConnection(file, ac); + URLConnection urlC = HTTPURL.getConnection(file, null, ac); is = HTTPURL.getInputStream(ac, urlC); url = urlC.getURL(); } @@ -444,7 +444,7 @@ "import URL sorry."); } - URLConnection importURL = HTTPURL.getConnection(importedURL, ac); + URLConnection importURL = HTTPURL.getConnection(importedURL, url, ac); String charset = HTTPURL.getCharacterEncoding(ac, importURL); if (importURL instanceof HttpURLConnection) { Index: org/w3c/css/servlet/CssValidator.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/servlet/CssValidator.java,v retrieving revision 1.51 diff -u -r1.51 CssValidator.java --- org/w3c/css/servlet/CssValidator.java 31 Oct 2011 13:22:33 -0000 1.51 +++ org/w3c/css/servlet/CssValidator.java 31 Oct 2011 18:38:53 -0000 @@ -366,7 +366,7 @@ // that it is a valid // url uri = uri.replaceAll(" ", "%20"); - DocumentParser URLparser = new DocumentParser(ac, uri); + DocumentParser URLparser = new DocumentParser(ac, uri, req.getHeader("Referer")); handleRequest(ac, res, uri, URLparser.getStyleSheet(), output, warningLevel, errorReport); Index: org/w3c/css/util/HTTPURL.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/util/HTTPURL.java,v retrieving revision 1.24 diff -u -r1.24 HTTPURL.java --- org/w3c/css/util/HTTPURL.java 23 Aug 2011 09:23:50 -0000 1.24 +++ org/w3c/css/util/HTTPURL.java 31 Oct 2011 18:38:53 -0000 @@ -151,9 +151,9 @@ return new URL(base, url); } - private static URLConnection getConnection(URL url, int count) + private static URLConnection getConnection(URL url, URL referrer, int count) throws IOException { - return getConnection(url, count, null); + return getConnection(url, referrer, count, null); } @@ -191,7 +191,7 @@ 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) { @@ -223,6 +223,7 @@ // for the fun urlC.setRequestProperty("User-Agent", "Jigsaw/2.2.5 W3C_CSS_Validator_JFouffa/2.0"); + addReferrer(urlC, referrer); // relay authorization information if (ac.getCredential() != null) { urlC.setRequestProperty("Authorization", ac.getCredential()); @@ -268,7 +269,7 @@ case 307: try { URL u = getURL(httpURL.getHeaderField("Location")); - return getConnection(u, count + 1, ac); + return getConnection(u, url, count + 1, ac); } finally { httpURL.disconnect(); } @@ -297,14 +298,14 @@ return urlC; } - public static URLConnection getConnection(URL url) + public static URLConnection getConnection(URL url, URL referrer) throws IOException { - return getConnection(url, 0); + return getConnection(url, referrer, 0); } - public static URLConnection getConnection(URL url, ApplContext ac) + public static URLConnection getConnection(URL url, URL referrer, ApplContext ac) throws IOException { - return getConnection(url, 0, ac); + return getConnection(url, referrer, 0, ac); } /* more madness */ @@ -358,6 +359,22 @@ return charset; } + private static void addReferrer(URLConnection urlC, URL referrer) { + if (referrer == null) + return; + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3 + if ("https".equals(referrer.getProtocol())) { + if ("https".equals(urlC.getURL().getProtocol())) { + urlC.setRequestProperty("Referer", referrer.toString()); + } + } else if ("http".equals(urlC.getURL().getProtocol())) { + if ("http".equals(referrer.getProtocol()) || + "ftp".equals(referrer.getProtocol())) { + urlC.setRequestProperty("Referer", referrer.toString()); + } + } + } + /** * */ @@ -365,7 +382,7 @@ throws Exception { int c; InputStream in = HTTPURL.getConnection( - getURL(args[0])).getInputStream(); + getURL(args[0]), null).getInputStream(); while ((c = in.read()) != -1) { System.err.print((char) c);