List of usage examples for java.net HttpCookie isHttpOnly
public boolean isHttpOnly()
From source file:Main.java
public static void main(String[] args) throws Exception { CookieManager cm = new CookieManager(); cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cm); new URL("http://google.com").openConnection().getContent(); List<HttpCookie> cookies = cm.getCookieStore().getCookies(); for (HttpCookie cookie : cookies) { System.out.println(cookie.isHttpOnly()); System.out.println();/* w w w . j ava 2 s . co m*/ } }
From source file:keywhiz.cli.JsonCookie.java
public static JsonCookie fromHttpCookie(HttpCookie cookie) { return JsonCookie.create(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getSecure(), cookie.isHttpOnly()); }
From source file:com.github.parisoft.resty.utils.CookieUtils.java
public static String toString(HttpCookie... cookies) { if (isEmpty(cookies)) { return null; }/*from w ww . j a v a 2s.c o m*/ final StringBuilder cookieBuilder = new StringBuilder(); for (HttpCookie cookie : cookies) { cookieBuilder.append(cookie.getName()).append("=").append(cookie.getValue()); if (cookie.getComment() != null) { cookieBuilder.append(";").append("Comment=").append(cookie.getComment()); } if (cookie.getDomain() != null) { cookieBuilder.append(";").append("Domain=").append(cookie.getDomain()); } if (cookie.getPath() != null) { cookieBuilder.append(";").append("Path=").append(cookie.getPath()); } if (cookie.getSecure()) { cookieBuilder.append(";").append("Secure"); } if (cookie.isHttpOnly()) { cookieBuilder.append(";").append("HttpOnly"); } if (cookie.getVersion() > 0) { cookieBuilder.append(";").append("Version=").append(cookie.getVersion()); } if (cookie.hasExpired()) { cookieBuilder.append(";").append("Max-Age=0"); } else { cookieBuilder.append(";").append("Max-Age=").append(cookie.getMaxAge()); } cookieBuilder.append(", "); } return cookieBuilder.deleteCharAt(cookieBuilder.length() - 1).toString(); }
From source file:com.muk.services.security.DefaultUaaLoginService.java
private String httpCookieToString(HttpCookie cookie) { final OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC).plusSeconds(cookie.getMaxAge()); final String cookieExpires = DateTimeFormatter.RFC_1123_DATE_TIME.format(now); final StringBuilder cookieBuilder = new StringBuilder(); cookieBuilder.append(cookie.getName()).append("=").append(cookie.getValue()).append(";path=") .append(cookie.getPath()).append(";max-age=").append(cookie.getMaxAge()).append(";expires=") .append(cookieExpires);// www. j av a 2 s .c om if (cookie.isHttpOnly()) { cookieBuilder.append(";HttpOnly"); } return cookieBuilder.toString(); }
From source file:org.zaproxy.zap.utils.HarUtils.java
public static HarResponse createHarResponse(HttpMessage httpMessage) { HttpResponseHeader responseHeader = httpMessage.getResponseHeader(); HarCookies harCookies = new HarCookies(); long whenCreated = System.currentTimeMillis(); for (HttpCookie cookie : responseHeader.getHttpCookies()) { Date expires;//from w w w.java2s . co m if (cookie.getVersion() == 0) { expires = new Date(whenCreated + (cookie.getMaxAge() * 1000)); } else { expires = new Date(httpMessage.getTimeSentMillis() + httpMessage.getTimeElapsedMillis() + (cookie.getMaxAge() * 1000)); } harCookies.addCookie(new HarCookie(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), expires, cookie.isHttpOnly(), cookie.getSecure(), null)); } String text = null; String encoding = null; String contentType = responseHeader.getHeader(HttpHeader.CONTENT_TYPE); if (contentType == null) { contentType = ""; } else if (!contentType.isEmpty()) { String lcContentType = contentType.toLowerCase(Locale.ROOT); final int pos = lcContentType.indexOf(';'); if (pos != -1) { lcContentType = lcContentType.substring(0, pos).trim(); } if (!lcContentType.startsWith("text")) { encoding = "base64"; text = Base64.encodeBytes(httpMessage.getResponseBody().getBytes()); } else { text = httpMessage.getResponseBody().toString(); } } HarContent harContent = new HarContent(httpMessage.getResponseBody().length(), 0, contentType, text, encoding, null); String redirectUrl = responseHeader.getHeader(HttpHeader.LOCATION); return new HarResponse(responseHeader.getStatusCode(), responseHeader.getReasonPhrase(), responseHeader.getVersion(), harCookies, createHarHeaders(responseHeader), harContent, redirectUrl == null ? "" : redirectUrl, responseHeader.toString().length(), httpMessage.getResponseBody().length(), null); }