From f4b20ca9e43b603979fbe89d73d8c662dbd01af2 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 22 Jan 2014 21:31:58 +0100 Subject: [PATCH] adding some configuration flags --- .../google/gwt/query/vm/AjaxTransportJre.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java index 015dcc94..166fa3b4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java @@ -29,13 +29,27 @@ public class AjaxTransportJre implements AjaxTransport { private static CookieManager cookieManager = CookieManager.getInstance(); - public static boolean debugOutput = false; + private static boolean debugOutput = false; + + private static boolean followRedirections = true; public static void enableCORS(String domain) { localDomain = domain; System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); } + public static void enableDebug(boolean b) { + debugOutput = b; + } + + public static void enableCookies(boolean b) { + cookieManager = b ? CookieManager.getInstance() : null; + } + + public static void enableRedirections(boolean b) { + followRedirections = b; + } + private final String USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0"; private final String jsonpCbRexp = "(?ms)^.*jre_callback\\((.*)\\).*$"; @@ -95,12 +109,17 @@ public class AjaxTransportJre implements AjaxTransport { URL u = new URL(url); HttpURLConnection c = (HttpURLConnection) u.openConnection(); + + c.setInstanceFollowRedirects(followRedirections); + c.setRequestMethod(s.getType()); c.setRequestProperty("User-Agent", USER_AGENT); if (s.getUsername() != null && s.getPassword() != null) { c.setRequestProperty ("Authorization", "Basic " + Base64Utils.toBase64((s.getUsername() + ":" + s.getPassword()).getBytes())); } - cookieManager.setCookies(c); + if (cookieManager != null) { + cookieManager.setCookies(c); + } boolean isCORS = cors && localDomain != null && !s.getUrl().contains(localDomain); if (isCORS) { @@ -160,8 +179,11 @@ public class AjaxTransportJre implements AjaxTransport { response.append(inputLine + "\n"); } in.close(); - - cookieManager.storeCookies(c); + + if (cookieManager != null) { + cookieManager.storeCookies(c); + } + return new ResponseJre(code, c.getResponseMessage(), response.toString(), c.getHeaderFields()); } -- 2.39.5