From: <rb...@us...> - 2013-10-09 18:28:31
|
Revision: 8636 http://sourceforge.net/p/htmlunit/code/8636 Author: rbri Date: 2013-10-09 18:28:28 +0000 (Wed, 09 Oct 2013) Log Message: ----------- revert fix for 1352 because it breaks backward compatibility Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-09 18:28:28 UTC (rev 8636) @@ -41,9 +41,6 @@ <action type="fix" dev="rbri" issue="1524"> Some debug log output added if HTMLDocument.canAlreadyBeParsed(String) returns false. </action> - <action type="fix" dev="rbri" issue="1352"> - Caching now works for encoded URLs also. - </action> <action type="update" dev="asashour"> Deprecate KeyDataPair. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -15,7 +15,6 @@ package com.gargoylesoftware.htmlunit; import java.io.Serializable; -import java.net.URL; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -34,7 +33,6 @@ * @version $Revision$ * @author Marc Guillemot * @author Daniel Gredler - * @author Ronald Brill */ public class Cache implements Serializable { @@ -95,25 +93,11 @@ * @param response the response corresponding to the specified compiled script * @param toCache the object that is to be cached, if possible (may be for instance a compiled script or * simply a WebResponse) - * @deprecated as of 2.13, please use {@link Cache#cacheIfPossible(URL, WebResponse, Object)} */ - @Deprecated public void cacheIfPossible(final WebRequest request, final WebResponse response, final Object toCache) { - cacheIfPossible(request.getUrl(), response, toCache); - } - - /** - * Caches the specified object, if the corresponding request and response objects indicate - * that it is cacheable. - * - * @param url the cache key - * @param response the response corresponding to the specified compiled script - * @param toCache the object that is to be cached, if possible (may be for instance a compiled script or - * simply a WebResponse) - */ - public void cacheIfPossible(final URL url, final WebResponse response, final Object toCache) { - if (isCacheable(response)) { - final Entry entry = new Entry(url.toString(), toCache); + if (isCacheable(request, response)) { + final String url = response.getWebRequest().getUrl().toString(); + final Entry entry = new Entry(url, toCache); entries_.put(entry.key_, entry); deleteOverflow(); } @@ -154,20 +138,8 @@ * @param request the performed request * @param response the received response * @return <code>true</code> if the response can be cached - * @deprecated as of 2.13, please use {@link Cache#isCacheable(WebResponse)} */ - @Deprecated protected boolean isCacheable(final WebRequest request, final WebResponse response) { - return isCacheable(response); - } - - /** - * Determines if the specified response can be cached. - * - * @param response the received response - * @return <code>true</code> if the response can be cached - */ - protected boolean isCacheable(final WebResponse response) { return HttpMethod.GET == response.getWebRequest().getHttpMethod() && !isDynamicContent(response); } @@ -235,22 +207,12 @@ * * @param request the request whose corresponding cached compiled script is sought * @return the cached object corresponding to the specified request if any - * @deprecated as of 2.13, please use {@link Cache#getCachedObject(URL)} */ - @Deprecated public Object getCachedObject(final WebRequest request) { - return getCachedObject(request.getUrl()); - } - - /** - * Returns the cached object corresponding to the specified request. If there is - * no corresponding cached object, this method returns <tt>null</tt>. - * - * @param url the cache key - * @return the cached object corresponding to the specified request if any - */ - public Object getCachedObject(final URL url) { - final Entry cachedEntry = entries_.get(url.toString()); + if (HttpMethod.GET != request.getHttpMethod()) { + return null; + } + final Entry cachedEntry = entries_.get(request.getUrl().toString()); if (cachedEntry == null) { return null; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -1271,11 +1271,8 @@ addDefaultHeaders(webRequest); // Retrieve the response, either from the cache or from the server. + final Object fromCache = getCache().getCachedObject(webRequest); final WebResponse webResponse; - Object fromCache = null; - if (HttpMethod.GET == webRequest.getHttpMethod()) { - fromCache = getCache().getCachedObject(url); - } if (fromCache != null && fromCache instanceof WebResponse) { webResponse = new WebResponseFromCache((WebResponse) fromCache, webRequest); } @@ -1286,7 +1283,7 @@ catch (final NoHttpResponseException e) { return new WebResponse(responseDataNoHttpResponse_, webRequest, 0); } - getCache().cacheIfPossible(url, webResponse, webResponse); + getCache().cacheIfPossible(webRequest, webResponse, webResponse); } // Continue according to the HTTP status code. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -1090,7 +1090,7 @@ request.setAdditionalHeader("Referer", referringRequest.getUrl().toString()); request.setAdditionalHeader("Accept", client.getBrowserVersion().getScriptAcceptHeader()); - final Object cachedScript = cache.getCachedObject(url); + final Object cachedScript = cache.getCachedObject(request); if (cachedScript instanceof Script) { return (Script) cachedScript; } @@ -1143,7 +1143,7 @@ final JavaScriptEngine javaScriptEngine = client.getJavaScriptEngine(); final Script script = javaScriptEngine.compile(this, scriptCode, url.toExternalForm(), 1); if (script != null) { - cache.cacheIfPossible(url, response, script); + cache.cacheIfPossible(request, response, script); } return script; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -72,7 +72,6 @@ import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Cache; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; -import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; @@ -304,14 +303,11 @@ request.setAdditionalHeader("Referer", referer); } - final URL reqUrl = request.getUrl(); - Object fromCache = null; + uri = request.getUrl().toExternalForm(); final Cache cache = client.getCache(); - if (HttpMethod.GET == request.getHttpMethod()) { - fromCache = cache.getCachedObject(reqUrl); - } + final Object fromCache = cache.getCachedObject(request); if (fromCache != null && fromCache instanceof org.w3c.dom.css.CSSStyleSheet) { - sheet = new CSSStyleSheet(element, (org.w3c.dom.css.CSSStyleSheet) fromCache, reqUrl.toExternalForm()); + sheet = new CSSStyleSheet(element, (org.w3c.dom.css.CSSStyleSheet) fromCache, uri); } else { final WebResponse response = client.loadWebResponse(request); @@ -323,7 +319,7 @@ source.setByteStream(response.getContentAsStream()); source.setEncoding(response.getContentCharset()); sheet = new CSSStyleSheet(element, source, uri); - cache.cacheIfPossible(reqUrl, response, sheet.getWrappedSheet()); + cache.cacheIfPossible(request, response, sheet.getWrappedSheet()); } } catch (final FailingHttpStatusCodeException e) { |