use of java.net.HttpCookie in project android by cSploit.
the class RequestParser method getCookiesFromHeaders.
public static ArrayList<HttpCookie> getCookiesFromHeaders(ArrayList<String> headers) {
ArrayList<String> values = getHeaderValues("Cookie", headers);
if (values != null && values.size() > 0) {
ArrayList<HttpCookie> cookies = new ArrayList<HttpCookie>();
for (String value : values) {
ArrayList<HttpCookie> lineCookies = parseRawCookie(value);
if (lineCookies != null && lineCookies.size() > 0) {
cookies.addAll(lineCookies);
}
}
// remove google and cloudflare cookies
Iterator<HttpCookie> it = cookies.iterator();
while (it.hasNext()) {
HttpCookie cookie = it.next();
if (cookie.getName().startsWith("__utm") || cookie.getName().equals("__cfduid"))
it.remove();
}
return cookies.size() > 0 ? cookies : null;
}
return null;
}
use of java.net.HttpCookie in project android by cSploit.
the class Session method save.
public String save(String sessionName) throws IOException {
StringBuilder builder = new StringBuilder();
String filename = System.getStoragePath() + '/' + sessionName + ".dhs", buffer = null;
builder.append(System.SESSION_MAGIC + "\n");
builder.append(mUserName == null ? "null" : mUserName).append("\n");
builder.append(mHTTPS).append("\n");
builder.append(mAddress).append("\n");
builder.append(mDomain).append("\n");
builder.append(mUserAgent).append("\n");
builder.append(mCookies.size()).append("\n");
for (HttpCookie cookie : mCookies.values()) {
builder.append(cookie.getName()).append("=").append(cookie.getValue()).append("; domain=").append(cookie.getDomain()).append("; path=/").append(mHTTPS ? ";secure" : "").append("\n");
}
buffer = builder.toString();
FileOutputStream ostream = new FileOutputStream(filename);
GZIPOutputStream gzip = new GZIPOutputStream(ostream);
gzip.write(buffer.getBytes());
gzip.close();
return filename;
}
use of java.net.HttpCookie in project android by cSploit.
the class Session method load.
public static Session load(String filename) throws Exception {
Session session;
File file = new File(System.getStoragePath() + '/' + filename);
if (file.exists() && file.length() > 0) {
BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file))));
String line;
// begin decoding procedure
try {
line = reader.readLine();
if (line == null || !line.equals(System.SESSION_MAGIC))
throw new Exception("Not a cSploit hijacker session file.");
session = new Session();
session.mUserName = decodeLine(reader);
session.mHTTPS = decodeBoolean(reader);
session.mAddress = decodeLine(reader);
session.mDomain = decodeLine(reader);
session.mUserAgent = decodeLine(reader);
for (int i = 0, ncookies = decodeInteger(reader); i < ncookies; i++) {
ArrayList<HttpCookie> cookies = RequestParser.parseRawCookie(reader.readLine());
for (HttpCookie cookie : cookies) {
session.mCookies.put(cookie.getName(), cookie);
}
}
reader.close();
} catch (Exception e) {
reader.close();
throw e;
}
} else
throw new Exception(filename + " does not exists or is empty.");
return session;
}
use of java.net.HttpCookie in project jetty.project by eclipse.
the class HttpCookieTest method test_CookieIsStored.
@Test
public void test_CookieIsStored() throws Exception {
final String name = "foo";
final String value = "bar";
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.addCookie(new Cookie(name, value));
baseRequest.setHandled(true);
}
});
String host = "localhost";
int port = connector.getLocalPort();
String path = "/path";
String uri = scheme + "://" + host + ":" + port + path;
Response response = client.GET(uri);
Assert.assertEquals(200, response.getStatus());
List<HttpCookie> cookies = client.getCookieStore().get(URI.create(uri));
Assert.assertNotNull(cookies);
Assert.assertEquals(1, cookies.size());
HttpCookie cookie = cookies.get(0);
Assert.assertEquals(name, cookie.getName());
Assert.assertEquals(value, cookie.getValue());
}
use of java.net.HttpCookie in project jetty.project by eclipse.
the class HttpCookieTest method test_PerRequestCookieIsSent.
@Test
public void test_PerRequestCookieIsSent() throws Exception {
final String name = "foo";
final String value = "bar";
start(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
Cookie[] cookies = request.getCookies();
Assert.assertNotNull(cookies);
Assert.assertEquals(1, cookies.length);
Cookie cookie = cookies[0];
Assert.assertEquals(name, cookie.getName());
Assert.assertEquals(value, cookie.getValue());
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).cookie(new HttpCookie(name, value)).timeout(5, TimeUnit.SECONDS).send();
Assert.assertEquals(200, response.getStatus());
}
Aggregations