Search in sources :

Example 71 with HttpCookie

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;
}
Also used : ArrayList(java.util.ArrayList) HttpCookie(java.net.HttpCookie)

Example 72 with HttpCookie

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;
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) HttpCookie(java.net.HttpCookie)

Example 73 with HttpCookie

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;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) HttpCookie(java.net.HttpCookie) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 74 with HttpCookie

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());
}
Also used : HttpCookie(java.net.HttpCookie) Cookie(javax.servlet.http.Cookie) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HttpServletResponse(javax.servlet.http.HttpServletResponse) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Response(org.eclipse.jetty.client.api.Response) HttpCookie(java.net.HttpCookie) Test(org.junit.Test)

Example 75 with HttpCookie

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HttpCookie(java.net.HttpCookie) Cookie(javax.servlet.http.Cookie) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) HttpCookie(java.net.HttpCookie) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) Test(org.junit.Test)

Aggregations

HttpCookie (java.net.HttpCookie)148 CookieManager (java.net.CookieManager)49 CookieStore (java.net.CookieStore)33 URI (java.net.URI)31 Test (org.junit.Test)31 IOException (java.io.IOException)14 Test (org.testng.annotations.Test)13 MockResponse (com.google.mockwebserver.MockResponse)11 MockWebServer (com.google.mockwebserver.MockWebServer)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Project (com.kickstarter.models.Project)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)5 URL (java.net.URL)5 Cookie (javax.servlet.http.Cookie)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 MockWebServer (okhttp3.mockwebserver.MockWebServer)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5