use of java.net.CookieHandler in project j2objc by google.
the class IosHttpURLConnection method loadRequestCookies.
/**
* Add any cookies for this URI to the request headers.
*/
private void loadRequestCookies() throws IOException {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler != null) {
try {
URI uri = getURL().toURI();
Map<String, List<String>> cookieHeaders = cookieHandler.get(uri, getHeaderFieldsDoNotForceResponse());
for (Map.Entry<String, List<String>> entry : cookieHeaders.entrySet()) {
String key = entry.getKey();
if (("Cookie".equalsIgnoreCase(key) || "Cookie2".equalsIgnoreCase(key)) && !entry.getValue().isEmpty()) {
List<String> cookies = entry.getValue();
StringBuilder sb = new StringBuilder();
for (int i = 0, size = cookies.size(); i < size; i++) {
if (i > 0) {
sb.append("; ");
}
sb.append(cookies.get(i));
}
setHeader(key, sb.toString());
}
}
} catch (URISyntaxException e) {
throw new IOException(e);
}
}
}
use of java.net.CookieHandler in project XobotOS by xamarin.
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().setStatusLine(getRequestLine());
if (requestHeaders.getUserAgent() == null) {
requestHeaders.setUserAgent(getDefaultUserAgent());
}
if (requestHeaders.getHost() == null) {
requestHeaders.setHost(getOriginAddress(policy.getURL()));
}
if (httpMinorVersion > 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 = CookieHandler.getDefault();
if (cookieHandler != null) {
requestHeaders.addCookies(cookieHandler.get(uri, requestHeaders.getHeaders().toMultimap()));
}
}
use of java.net.CookieHandler in project intellij-plugins by StepicOrg.
the class AuthDialog method initCookieManager.
@NotNull
private CookieManager initCookieManager(boolean clearCookies) {
CookieHandler cookieManager = CookieManager.getDefault();
if (!(cookieManager instanceof CookieManager)) {
cookieManager = new CookieManager();
}
if (clearCookies) {
((CookieManager) cookieManager).clear();
clearedCookies = true;
}
CookieManager.setDefault(cookieManager);
return (CookieManager) cookieManager;
}
use of java.net.CookieHandler in project QuickAndroid by ImKarl.
the class OkHttpCacheHelper method networkRequest.
private static Request networkRequest(OkHttpClient client, Request request) throws IOException {
Request.Builder result = request.newBuilder();
if (request.header("Host") == null) {
result.header("Host", Util.hostHeader(request.httpUrl()));
}
if (request.header("Connection") == null) {
result.header("Connection", "Keep-Alive");
}
if (request.header("Accept-Encoding") == null) {
result.header("Accept-Encoding", "gzip");
}
CookieHandler cookieHandler = client.getCookieHandler();
if (cookieHandler != null) {
// Capture the request headers added so far so that they can be offered to the CookieHandler.
// This is mostly to stay close to the RI; it is unlikely any of the headers above would
// affect cookie choice besides "Host".
Map<String, List<String>> headers = OkHeaders.toMultimap(result.build().headers(), null);
Map<String, List<String>> cookies = cookieHandler.get(request.uri(), headers);
// Add any new cookies to the request.
OkHeaders.addCookies(result, cookies);
}
if (request.header("User-Agent") == null) {
result.header("User-Agent", Version.userAgent());
}
return result.build();
}
use of java.net.CookieHandler in project j2objc by google.
the class IosHttpURLConnection method saveResponseCookies.
/**
* Store any returned cookies.
*/
private void saveResponseCookies() throws IOException {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler != null) {
try {
URI uri = getURL().toURI();
cookieHandler.put(uri, getHeaderFieldsDoNotForceResponse());
} catch (URISyntaxException e) {
throw new IOException(e);
}
}
}
Aggregations