use java.net.HttpCookie instead of Crockfords json.org
The org.json.Cookie class from Crockfords json.org library is licensed under
an MIT like license but with an added clause:
"The Software shall be used for Good, not Evil."
For this reasons the library is considered non-free software by Google,
Debian, Fedora and others. The android project wrote a white room
reimplementation[1] but it does not (yet) include the Cookie class.
[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=697311
Issue: http://code.google.com/p/google-web-toolkit/issues/detail?id=7885
Change-Id: If3568a459f7a196140fa7af5b38850716a71fdd6
Review-Link: https://gwt-review.googlesource.com/#/c/1600/
Review by: skybrian@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11457 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/web/bindery/requestfactory/vm/testing/UrlRequestTransport.java b/user/src/com/google/web/bindery/requestfactory/vm/testing/UrlRequestTransport.java
index 06b4f12..183d399 100644
--- a/user/src/com/google/web/bindery/requestfactory/vm/testing/UrlRequestTransport.java
+++ b/user/src/com/google/web/bindery/requestfactory/vm/testing/UrlRequestTransport.java
@@ -19,14 +19,11 @@
import com.google.web.bindery.requestfactory.shared.RequestTransport;
import com.google.web.bindery.requestfactory.shared.ServerFailure;
-import org.json.Cookie;
-import org.json.JSONException;
-import org.json.JSONObject;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.HttpCookie;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
@@ -97,18 +94,22 @@
List<String> cookieHeaders = connection.getHeaderFields().get("Set-Cookie");
if (cookieHeaders != null) {
for (String header : cookieHeaders) {
+ List<HttpCookie> headerCookies;
try {
- JSONObject cookie = Cookie.toJSONObject(header);
- String name = cookie.getString("name");
- String value = cookie.getString("value");
- String domain = cookie.optString("Domain");
+ headerCookies = HttpCookie.parse(header);
+ } catch (IllegalArgumentException e) {
+ // if we can't parse it, ignore it
+ continue;
+ }
+
+ for (HttpCookie cookie : headerCookies) {
+ String domain = cookie.getDomain();
if (domain == null || url.getHost().endsWith(domain)) {
- String path = cookie.optString("Path");
+ String path = cookie.getPath();
if (path == null || url.getPath().startsWith(path)) {
- cookies.put(name, value);
+ cookies.put(cookie.getName(), cookie.getValue());
}
}
- } catch (JSONException ignored) {
}
}
}