Search in sources :

Example 11 with CookieHandler

use of java.net.CookieHandler in project cordova-android-chromeview by thedracle.

the class HttpEngine method prepareRawRequestHeaders.

/**
   * Populates requestHeaders with defaults and cookies.
   *
   * <p>This client doesn't specify a default {@code Accept} header because it
   * doesn't know what content types the application is interested in.
   */
private void prepareRawRequestHeaders() throws IOException {
    requestHeaders.getHeaders().setRequestLine(getRequestLine());
    if (requestHeaders.getUserAgent() == null) {
        requestHeaders.setUserAgent(getDefaultUserAgent());
    }
    if (requestHeaders.getHost() == null) {
        requestHeaders.setHost(getOriginAddress(policy.getURL()));
    }
    if ((connection == null || connection.getHttpMinorVersion() != 0) && requestHeaders.getConnection() == null) {
        requestHeaders.setConnection("Keep-Alive");
    }
    if (requestHeaders.getAcceptEncoding() == null) {
        transparentGzip = true;
        requestHeaders.setAcceptEncoding("gzip");
    }
    if (hasRequestBody() && requestHeaders.getContentType() == null) {
        requestHeaders.setContentType("application/x-www-form-urlencoded");
    }
    long ifModifiedSince = policy.getIfModifiedSince();
    if (ifModifiedSince != 0) {
        requestHeaders.setIfModifiedSince(new Date(ifModifiedSince));
    }
    CookieHandler cookieHandler = policy.cookieHandler;
    if (cookieHandler != null) {
        requestHeaders.addCookies(cookieHandler.get(uri, requestHeaders.getHeaders().toMultimap(false)));
    }
}
Also used : Date(java.util.Date) CookieHandler(java.net.CookieHandler)

Example 12 with CookieHandler

use of java.net.CookieHandler in project XobotOS by xamarin.

the class HttpEngine method readHeaders.

private void readHeaders(RawHeaders headers) throws IOException {
    // parse the result headers until the first blank line
    String line;
    while (!(line = Streams.readAsciiLine(socketIn)).isEmpty()) {
        headers.addLine(line);
    }
    CookieHandler cookieHandler = CookieHandler.getDefault();
    if (cookieHandler != null) {
        cookieHandler.put(uri, headers.toMultimap());
    }
}
Also used : CookieHandler(java.net.CookieHandler)

Example 13 with CookieHandler

use of java.net.CookieHandler in project jdk8u_jdk by JetBrains.

the class HttpOnly method test.

void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    CookieHandler previousHandler = CookieHandler.getDefault();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH);
        populateCookieStore(uri);
        doClient(uri);
    } finally {
        CookieHandler.setDefault(previousHandler);
        server.stop(0);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) URI(java.net.URI) CookieHandler(java.net.CookieHandler)

Aggregations

CookieHandler (java.net.CookieHandler)13 URI (java.net.URI)4 Date (java.util.Date)4 IOException (java.io.IOException)3 List (java.util.List)3 URISyntaxException (java.net.URISyntaxException)2 Map (java.util.Map)2 KeyEvent (android.view.KeyEvent)1 SurfaceView (android.view.SurfaceView)1 View (android.view.View)1 OnKeyListener (android.view.View.OnKeyListener)1 FrameLayout (android.widget.FrameLayout)1 AspectRatioFrameLayout (com.google.android.exoplayer.AspectRatioFrameLayout)1 AudioCapabilitiesReceiver (com.google.android.exoplayer.audio.AudioCapabilitiesReceiver)1 Request (com.squareup.okhttp.Request)1 HttpServer (com.sun.net.httpserver.HttpServer)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1