forked from j62/ctbrec
Remove guest session cookies on start for LiveJasmin
This commit is contained in:
parent
44bc5d02aa
commit
0417fd6bfb
|
@ -34,7 +34,7 @@ public class CookieJarImpl implements CookieJar {
|
|||
String name = oldCookie.name();
|
||||
for (Cookie newCookie : cookies) {
|
||||
if(newCookie.name().equalsIgnoreCase(name)) {
|
||||
LOG.debug("Replacing cookie {} {} -> {} [{}]", oldCookie.name(), oldCookie.value(), newCookie.value(), oldCookie.domain());
|
||||
LOG.trace("Replacing cookie {} {} -> {} [{}]", oldCookie.name(), oldCookie.value(), newCookie.value(), oldCookie.domain());
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ public class CookieJarImpl implements CookieJar {
|
|||
}
|
||||
cookiesForUrl.addAll(cookies);
|
||||
cookieStore.put(host, cookiesForUrl);
|
||||
LOG.debug("Adding cookie: {} for {}", cookiesForUrl, host);
|
||||
LOG.trace("Adding cookie: {} for {}", cookiesForUrl, host);
|
||||
}
|
||||
else {
|
||||
cookieStore.put(host, cookies);
|
||||
LOG.debug("Storing cookie: {} for {}", cookies, host);
|
||||
LOG.trace("Storing cookie: {} for {}", cookies, host);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,9 +54,9 @@ public class CookieJarImpl implements CookieJar {
|
|||
public List<Cookie> loadForRequest(HttpUrl url) {
|
||||
String host = getDomain(url);
|
||||
List<Cookie> cookies = cookieStore.get(host);
|
||||
LOG.debug("Cookies for {}", url);
|
||||
LOG.trace("Cookies for {}", url);
|
||||
Optional.ofNullable(cookies).ifPresent(cookiez -> cookiez.forEach(c -> {
|
||||
LOG.debug(" {} expires on:{}", c, c.expiresAt());
|
||||
LOG.trace(" {} expires on:{}", c, c.expiresAt());
|
||||
}));
|
||||
//LOG.debug("Cookies for {}: {}", url.host(), cookies);
|
||||
return cookies != null ? cookies : new ArrayList<Cookie>();
|
||||
|
@ -72,6 +72,19 @@ public class CookieJarImpl implements CookieJar {
|
|||
throw new NoSuchElementException("No cookie named " + name + " for " + url.host() + " available");
|
||||
}
|
||||
|
||||
public void deleteCookie(HttpUrl url, String name) {
|
||||
List<Cookie> cookies = loadForRequest(url);
|
||||
for (Iterator<Cookie> iterator = cookies.iterator(); iterator.hasNext();) {
|
||||
Cookie cookie = iterator.next();
|
||||
if(Objects.equals(cookie.name(), name)) {
|
||||
iterator.remove();
|
||||
LOG.debug("Removed cookie \"{}\" for {}", name, url.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new NoSuchElementException("No cookie named " + name + " for " + url.host() + " available");
|
||||
}
|
||||
|
||||
private String getDomain(HttpUrl url) {
|
||||
// String host = url.host();
|
||||
// if (host.startsWith("www.")) {
|
||||
|
|
|
@ -20,6 +20,18 @@ public class LiveJasminHttpClient extends HttpClient {
|
|||
|
||||
protected LiveJasminHttpClient() {
|
||||
super("livejasmin");
|
||||
|
||||
// delete session, if we are guests, because old guest sessions cause
|
||||
// endless redirects
|
||||
if(Config.getInstance().getSettings().livejasminUsername.isEmpty()) {
|
||||
HttpUrl url = HttpUrl.parse("https://" + LiveJasmin.baseDomain);
|
||||
try {
|
||||
getCookieJar().deleteCookie(url, "session");
|
||||
} catch (NoSuchElementException e) {
|
||||
LOG.debug("Session cookie not found -> let's go!");
|
||||
// fine, no session cookie means we are good to go
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue